Android Question [ X2 ] How do I create a space map with parallax effect on the X2 of size 6144x6144?

Waldemar Lima

Well-Known Member
Licensed User
I created this using SDL drawer in C ++ , is there any more effective way to do this in b4x?

1618113368449.png
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot load such a large image.
You need to scale it down and make it smaller.

A more complex example of parallax effect, with multiple layers, is available in Clumy Bird example. The trick is to draw the background twice with different offsets. This allows you to make it an endless background.
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Creating such image will require more than 144MB (width * height * 4). It is likely to cause trouble.

but what is the most effective way to create a space-style map? large (6000x3000) so it’s not too heavy? create a struct to store the number of objects on the screen, and as the field of view changes, will it appear?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
You cannot load such a large image.
Sorry, I don't know much about X2 so this might be obvious to all involved... But I just have to ask: The image attached in the original post is less than 50kB (*). And the dimensions are 1919x1079. What makes it large? Looking at your math it would seem that it would take 1919pixels x 1079pixels x 4bytes = 8 282 404 bytes. So around 8MB. But you said 144 MB, so what am I missing?

(*) The image could easily be reduced to 1727 bytes if one used indexed colors instead (a 96% reduction). I have no idea if it's possible to use that in X2, or if it would affect the situation anything. Reduced image attached.
 

Attachments

  • 1618113368449b.png
    1618113368449b.png
    1.7 KB · Views: 105
Upvote 0

emexes

Expert
Licensed User
(*) The image could easily be reduced to 1727 bytes if one used indexed colors instead (a 96% reduction). I have no idea if it's possible to use that in X2, or if it would affect the situation anything.
Good thing you added this little proviso :cool: your indexed (and compressed) PNG doesn't have an alpha channel which is fine for the bottom layer but necessary for the parallax layers in front of that. I'm thinking GIF might result in a smaller equivalent (using transparency as a poor programmer's alpha) given that the original image is also only 2 unique colors.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I didn't see that the original had an alpha channel, but I remade my pic with transparency. :)

PNG: 1719 bytes
GIF: 3951 bytes
 

Attachments

  • transparent.png
    transparent.png
    1.7 KB · Views: 94
  • transparent.gif
    transparent.gif
    3.9 KB · Views: 96
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. The compressed image size is not important.
2. I was talking about the dimensions mentioned in the title (6144 * 6144).

The memory consumption of an image is about width * height * 4 bytes. Exact details depend on the loaded format (RGB565, ARGB, etc.).
Also note that the memory block should be contiguous which makes it more restricted.
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
thank you all for your attention :)

It depends on what you are trying to do.
I would like to make a game on X2, that the map would be the outer space in size (6144 * 6144), I wanted to draw the stars according to what the server sends to all users so that the map is exactly the same .
what do you recommend?
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
what do you recommend?
Please note that I know close to nothing about X2, nor about what you're trying to do, so take this with a huge chunk of salt. :) (I do, however, have a large number of hours spent coding demos on the C64 - oh, good times!)

My mental image is that you will have a screen with spaceships or something like that, and you want to have a starfield in the background. The field should move around, as the player moves their ship. Assuming this is correct, my first option would be to create each background star as its own entity. (Again, that might be insane for X2 - I have no idea.)

I would create, say, three arrays with star positions. This is a simple description:

Array 1, used for stars "very far away": 1 pixel per star, 50% white
Array 2, used for stars "a little closer": 1 pixel per star, 100% white
Array 3, used for stars "closest": 5 pixels per star (in a cross, like you had in your image), 100% white

When the user move in one direction I shift each star in each array in the opposite direction. Move stars in Array 1 a distance if Q pixels. Array 2 a distance of Q*2 pixels. Array 3 a distance of Q*3 pixels.

When a star is moved out of the screen, spawn a new star at a random position at the other far end so a new star is moved in. This way you will never have any repeating patterns in the stars.

Number of stars for each array is to be tested to make sure it looks good. As is the value for Q. Shouldn't be to hard to find good-looking values. :)
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
hello guys, thanks for the feedback, I tried to study the lib X2 a little, but it is quite difficult to implement it. What is the most effective way that you suggest me to create a game that the map is theoretically 6000 in width and 3000 in height with objects that will be generated in a procedural way to form the map and the player will be able to navigate freely wherever he feels like ?
 
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
in the screenshot below, I created this game using SDL in C ++ and it comes down to the following: All the stars are being drawn in a procedural way one by one using primitive drawing functions (DrawCircle & DrawLine), since the ship I am importing a sprite in PNG and drawing it on the screen together with the stars that are in the X and Y position that stay within the user's field of view (in the SDL I can draw only the stars that are in the player's field of view so that the game is more optimized), is there any way to do this with B4X in an easy way?

1619926553643.png1619926935585.png1619926958437.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Off screen sprites are never drawn. You can draw the stars yourself with the async drawing methods: https://www.b4x.com/android/forum/threads/xui2d-mouse-following-a-path.98895/#content

Another option is to create a large map of square static sprites. This way the game engine will handle the drawing for you.

I will try this way, thank you very much !

I would like to ask another question, wouldn't you think that you can make the X2 easier and more practical to use?
I talked to a group that uses b4x, and everyone has the same opinion about the X2 being complicated and not practical .
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I will explain the situation with X2 framework.

1. Many efforts were spent to build this framework.
2. You can build nice 2d games with X2. Even some of the examples are quite impressive.
3. X2 lead the way to many other cross platform features. The concepts behind B4XPages were first implemented while building X2 and the various examples.
BitmapCreator, BCTextEngine, b4xlibs, and many other recent things are derived from the work on X2.
4. Building real games, that run in 60 fps, is not simple. There is no magic. It is more complex than most types of apps.

5. There is an egg and chicken case here. X2 didn't get enough traction to justify further major development and on the other hand it is not mature enough.
6. The next improvement to X2 will be to make it based on B4XPages. It will make some things simpler.

Bottom line: Many good things came out of X2. I know that it is not mature enough and I plan to improve it over time.

 
Last edited:
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Something that excites me a lot is how fast the B4X has support and dedication, it is something done with love and sweat. I am immeasurably grateful for the dedication @Erel and his team for the immense job well done that they have done and are doing ...
 
Upvote 0
Top