dynamically load image to save memory

0 favourites
  • 6 posts
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • the viewport resolution: 854x480

    I have about 8 stars (background sprite) in the game but only 1 is shown on each level.

    stars range from 600x600 and larger - largest one is 1024x1024

    currently I have each frame of the 8 stars in one sprite (frame speed 0) and I just flip to the correct frame for the level the player is on.

    I assume this is wildly inefficient because the other frames are in memory taking up space when they aren't needed.

    In the past I dynamically switched (using the URL loader) the star image but sometimes the loading lagged and you the player saw the switch happen which was no good.

    any suggestions on how I should handle this?

  • Just to get a better picture, you say only one is shown per level, do your levels all take place within the same layout?

  • calminthenight yes that's the issue, I use one generic layout.

    EDIT: is there a way to load the image without any sort of lag or performance spike? is there a technique that people normally do to avoid the player seeing this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If you used separate sprites you could just load the next image into memory before it is actually needed and then when you switch to it there shouldn't be any lag.

    Have a trigger that happens when the player is almost about to transfer into the new level, and load the image into memory then. Then replace the image when you usually would.

    Or alternatively you could use a transition to hide anything going on in the background, like a fade to black with the new level name or something to cover up the change.

  • calminthenight

    If you used separate sprites you could just load the next image into memory before it is actually needed and then when you switch to it there shouldn't be any lag.

    oh do you mean make the sprite global then load the image from the previous layout? that is interesting. if the previous image was larger, would that "free up" memory when the new layout loaded? (I don't really mean free up, I just mean only load the new image size instead of the old size since its global?)

  • It doesn't need to be global. Just use the 'load object images action' for the sprite that you need prior to the time that you are going to switch to it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)