Preloading sprites into Video Memory issues

Discussion and feedback on Construct 2

Post » Sun Jul 13, 2014 8:35 am

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".
B
34
S
5
G
1
Posts: 78
Reputation: 3,397

Post » Sun Jul 13, 2014 8:40 am

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.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon Jul 14, 2014 1:29 am

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.
B
34
S
5
G
1
Posts: 78
Reputation: 3,397

Post » Mon Jul 14, 2014 1:41 am

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.
Image ImageImage
B
169
S
50
G
174
Posts: 8,328
Reputation: 110,800

Post » Mon Jul 14, 2014 10:38 am

newt wrote: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.
B
34
S
5
G
1
Posts: 78
Reputation: 3,397

Post » Mon Jul 14, 2014 12:28 pm

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.
Image ImageImage
B
169
S
50
G
174
Posts: 8,328
Reputation: 110,800

Post » Tue Jul 15, 2014 3:00 am

newt wrote: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?
B
34
S
5
G
1
Posts: 78
Reputation: 3,397

Post » Tue Jul 15, 2014 3:14 am

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.
Image ImageImage
B
169
S
50
G
174
Posts: 8,328
Reputation: 110,800

Post » Tue Jul 15, 2014 11:45 am

newt wrote: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.
B
12
S
3
Posts: 104
Reputation: 1,655

Post » Tue Jul 15, 2014 11:48 am

EddyDingDongs wrote: .... 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....
B
12
S
3
Posts: 104
Reputation: 1,655

Next

Return to Construct 2 General

Who is online

Users browsing this forum: adelwich, Yahoo [Bot] and 14 guests