Is there any way to ensure or a trick to do this?
Forum
CS2D Scripts Is there any way to change image order?Is there any way to change image order?
6 replies 1
Is there any way to ensure or a trick to do this?
@ VADemon: Images are always sent in reliable, ordered network packages so packet loss can't mess with their order.
@ 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 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.
MikuAuahDark has written
@ Cure Pikachu: How bad will be the performance
when creating 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.
when creating 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.
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 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 imagepos, imagescale, imagealpha, and imagecoor called on every frame? I think it's 4x slower than image but I'm curious to know it.
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.
1