English Is there any way to change image order?

6 replies
Goto Page
To the start Previous 1 Next To the start
Up
MikuAuahDark
User
Offline Off
Example: I have 2 images (image A and B). I want image B is drawn over image A with same image mode (like both image mode is 0, 1, or 2), but the order they created is not defined, so it's possible that image A is created first then image B or vice versa.

Is there any way to ensure or a trick to do this?
Retired from CS2D maybe? Or maybe Yohane for CS2D?
11.02.17 08:16:28 pm
Up
Cure Pikachu
User
Offline Off
The order the images are created should be determined by your script sequence, unless I am missing something. It's like stacking pancakes on top of one another.
Test Code >
file cs2d Customisable Time Display (6) - v3 released! file cs2d Map Callouts (10) - Currently v3.6!
11.02.17 09:00:54 pm
Up
VADemon
User
Offline Off
I think the image order can be messed up based on packet loss and while it should work in theory @user Cure Pikachu (I'd have proposed the same obviously), instead I have concerns.
Stranded 3 development     |     Looking for volunteers for CS2D-Archive. PM me.
12.02.17 04:34:45 am
Up
MikuAuahDark
User
Offline Off
@user Cure Pikachu: How bad will be the performance when creating cs2d lua cmd image on every frame (or I can say, for every 20ms)? I actually want to implement image caching, but it seems impossible because the image order is undefined.
Retired from CS2D maybe? Or maybe Yohane for CS2D?
12.02.17 12:47:01 pm
Up
DC
Admin
Offline Off
Like user Cure Pikachu says, the order is defined by the time of creation. The image you created last is always on top of all older ones.

@user VADemon: Images are always sent in reliable, ordered network packages so packet loss can't mess with their order.

@user MikuAuahDark: Unfortunately I can't think of a good solution for this. Here are some ideas but depending on what you're trying to do this might not work very well / at all:

If you know what sprites the images are going to use you could create them all beforehand in the right order and hide them (either set alpha to 0 or move them outside the visible area) until they are needed.

If you don't know which sprites are going to be used, you could still create the images beforehand but put all possible sprites in one big texture atlas and use multi frame sprites and change the frames as required with cs2d lua cmd imageframe.

The last resort would be to destroy and re-create images in the right order whenever you need to change the order. Note that this is quite expensive and traffic-heavy and will certainly lead to lags when you have many images.

user MikuAuahDark has written:
@user Cure Pikachu: How bad will be the performance
when creating cs2d lua cmd image on every frame (or I can say, for every 20ms)? I actually want to implement image caching, but it seems impossible because the image order is undefined.

Something like this should be avoided if possible. It might work well for one image without big performance issues but it will cause an ridiculous amount of network traffic over time.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
14.02.17 06:53:53 pm
Up
MikuAuahDark
User
Offline Off
@user DC: So looks like the best solution is to pre-load the images in right order, then set the opacity when needed.

user DC has written:
If you don't know which sprites are going to be used, you could still create the images beforehand but put all possible sprites in one big texture atlas and use multi frame sprites and change the frames as required with cs2d lua cmd imageframe.


Just a note, this method doesn't work in my situation. The script only calls my callback function which tells them "do x with this additional useful data. I don't care how and which function do you use to do x". In this case, the script calls my callback and tell it "draw this image with this information (scale, rotatation, position)". Also pre-rendering the animation requires too much work on my side, because the data is stored in a instruction-like system, which can loop from beginning or jump directly. To make it simple, I only have animation data sequence and image information to be used.

Out of curiosity, how bad the performance if cs2d lua cmd imagepos, cs2d lua cmd imagescale, cs2d lua cmd imagealpha, and cs2d lua cmd imagecoor called on every frame? I think it's 4x slower than cs2d lua cmd image but I'm curious to know it.
Retired from CS2D maybe? Or maybe Yohane for CS2D?
15.02.17 11:28:48 am
Up
DC
Admin
Offline Off
You would have to do a benchmark to test that...
I highly doubt that these 4 together are 4 times slower than creating a new image. I would assume that they are only slightly slower (if at all) because creating a new image is more expensive than changing an existing one.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
To the start Previous 1 Next To the start