Preloading sprites into Video Memory issues

1 favourites
From the Asset Store
Add SubRip (SRT) subtitles to your videos in Construct 3
  • In my game i create various sprites and animated sprites when they are needed.

    Now performance wise I get a smooth frame rate (50-60-fps) up until the points when these sprites are created.

    At which point I get stutters and pauses of the frame rate when these sprite objects are created.

    Now the only solution would be to create these sprites on start of layout and have them outside the layout boundaries, so they are invisible. BUT this doesn't work becos many of my sprites are coded to continue moving in one direction (as they are projectiles), and other sprites are coded to animate and keep on scaling, and other sprites are coded with the "Fade" behaviour, so even if they are created off layout they will only last for 3-seconds before they are destroyed by the fade behaviour. And once they are destroyed 3-seconds after layout start then they will be unloaded from video memory, thus negating all my efforts to preload a god damn texture!

    * I think this is a serious performance issue with C2, and should be put ontop of the priority list. Basically what I what is an Action added eg. On Start of Layout -> Preload Sprites -> from Family "XYZ".

  • The graphics are loaded layout by layout, however, if a sprite with a new graphic is created on the layout, it is effectively loaded, but it will not be unloaded later If my understanding of C2 is correct, unless you change to a layout that don't have them.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks for the info Aphrodite, not sure that sprites get unloaded only at end of layout, it seems like they get unloaded when the last sprite is deleted. I would like confirmation of this from Scirra.

  • C2 loads everything into memory at the start of layout, so the objects already exist in memory.

    There is no reason for the creation to cause a slow down.

    Perhaps something else is happening when you run the creation events.

  • C2 loads everything into memory at the start of layout, so the objects already exist in memory.

    There is no reason for the creation to cause a slow down.

    Perhaps something else is happening when you run the creation events.

    I'll explain a bit more, basically i have two "UNUSED" Layouts which I store my first instances of each sprite. This is necessary in my game as I have character selection and most of the sprites will not be used as only 2 out of 8 characters will only be in use at any one time.

    Thus I create these sprites (eg. special FX sprites & projectiles specific to each character) as they are needed and they do not exist on my level Layouts beforehand.

  • Nobody ever gives all the pertinent information.

    Leave the objects in the layout, and destroy them at the start of layout.

    The fact that loading the images into memory will slow it down can not be bypassed.

  • Nobody ever gives all the pertinent information.

    Leave the objects in the layout, and destroy them at the start of layout.

    The fact that loading the images into memory will slow it down can not be bypassed.

    So Newt, are you sure that no sprites get unloaded while a layout is active?

    Do sprites only get unloaded at end of a layout?

  • If you are using webgl everything gets loaded layout by layout.

    If not everything gets loaded at once, with the caveat that you can load textures via a url.

    A texture should not be unloaded while a layout is active, unless you overload memory.

    That's not to say some browser may do some weird stuff with garbage collection.

    Speaking of the hick-ups might also be attributed to the gigo.

  • C2 loads everything into memory at the start of layout, so the objects already exist in memory.

    There is no reason for the creation to cause a slow down.

    I experience the very same problem in my project: On my game at the end of every screen the game presenter pops in to congratulate the kid for completing his mission. At this point one of many possible animations is selected randomly. It is not possible to add all animations to all screens as it will create a huge load.

    Here is what I'm going to try: I will add a "mission-is-nearly-completed" trigger that will create the presenter's animation while the game is played so it is ready and well timed for mission complete climax. That should work.

    Ashley - I think that an Object Preload action could become handy for such cases, so you can run animations that are not included in the current layout without any delays.

  • .... and other sprites are coded with the "Fade" behaviour, so even if they are created off layout they will only last for 3-seconds before they are destroyed by the fade behaviour. And once they are destroyed 3-seconds after layout start then they will be unloaded from video memory, thus negating all my efforts to preload a god damn texture!

    This is a straight forward RTFM issue my friend.... Switch the fade's Destroy property to "No" and you are done....

  • There is no need for a preload feature. Construct 2 already preloads any objects placed on the layout. If you create an object at runtime which is not in the layout, it has to load it then and there, which can introduce a jank - so just place the object in the layout and destroy it on start of layout. They will still be preloaded. Any objects placed in the layout will not be unloaded until the end of the layout. Objects loaded at runtime may also be unloaded at runtime if the last instance is destroyed.

  • > .... and other sprites are coded with the "Fade" behaviour, so even if they are created off layout they will only last for 3-seconds before they are destroyed by the fade behaviour. And once they are destroyed 3-seconds after layout start then they will be unloaded from video memory, thus negating all my efforts to preload a god damn texture!

    >

    This is a straight forward RTFM issue my friend.... Switch the fade's Destroy property to "No" and you are done....

    I understand that, but for some particular sprites I need to have the destroy property to "yes", otherwise I won't know when to delete particular sprites. But according to some of you here nothing should be unloaded while a layout is active, so if that is true then it's not an issue.

  • There is no need for a preload feature. Construct 2 already preloads any objects placed on the layout. If you create an object at runtime which is not in the layout, it has to load it then and there, which can introduce a jank - so just place the object in the layout and destroy it on start of layout. They will still be preloaded. Any objects placed in the layout will not be unloaded until the end of the layout. Objects loaded at runtime may also be unloaded at runtime if the last instance is destroyed.

    Thank you Ashley, if you could please copy & paste what you just said into the Manual then it would avoid anyone else asking the same questions. You could add it to the "Sprites" section, i think that would be best since the optimization sections might not be reached as directly.

    Thank you again for your clarification and continued hard work, recent performance improvements for PC under nodewebkit have been very awesome!

  • I understand that, but for some particular sprites I need to have the destroy property to "yes", otherwise I won't know when to delete particular sprites. But according to some of you here nothing should be unloaded while a layout is active, so if that is true then it's not an issue.

    A "DestroyMe" variable on these objects may help you to do so without using the Destroy after fade option.

  • There is no need for a preload feature. Construct 2 already preloads any objects placed on the layout. If you create an object at runtime which is not in the layout, it has to load it then and there, which can introduce a jank - so just place the object in the layout and destroy it on start of layout. They will still be preloaded. Any objects placed in the layout will not be unloaded until the end of the layout. Objects loaded at runtime may also be unloaded at runtime if the last instance is destroyed.

    Ashley I am a bit confused here. Say that the layout does include one instance for each required object. Naturally the objects will load with the layout. But immidiatly after that you suggest to destroy the objects. Wouldn't these objects be unloaded since the last instance is destroyed???

    The suggested method is not very practical in my case. It is not reasonable to load all presenter animations when the layout will eventually use only one (randomly selected). My solution is to create a random presenter animation and place it offsscreen while the layout is being played, so it is ready for use when needed. This is actually an a bit lame but effective gfx preload procedure.

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