Preloading images? FPS issue

Discussion and feedback on Construct 2

Post » Wed Dec 12, 2012 4:57 am

I'm having some performance issues that I feel are being caused by sprites loading on creation instead of being loaded at the start.

I have about 6 *heavy* sprites (heavy meaning over 100 frames of animation in a 128x128 dimension image) which seem to be causing me problems.

The thing is, my game runs at a nice steady framerate until these sprites need to be created. Then it nosedives for a couple of seconds until the sprite is "loaded". But doesn't Construct 2 load this stuff at the start?

Further evidence that the sprite creation is the problem, is that after a while, my game's framerate actually improves overall, even with more of these sprites on screen. Which tells me that now they are "loaded" and not causing stress on the hardware.

Is there some way to preload sprites or images? Is there a way to preload other things as well? I thought perhaps setting the sprites to global and putting them in another layout, they would be "preloaded" but this doesn't really seem to be working.

So what's the deal?
B
7
S
2
G
3
Posts: 28
Reputation: 2,260

Post » Wed Dec 12, 2012 5:56 am

Are you using webgl? If so, c2 is using layout-by-layout loading - meaning anything not in the layout is dumped from memory. When you create an instance, it needs to be loaded again - resulting in a pause while it does so.

To eliminate the pause, either keep it in the game as a global object or create an instance at the beginning of the layout and keep it invisible instead.

I haven't tried it yet, but c2 also might not unload the sprite from memory when there are no instances if it was in the layout at from the start at edit time. That's just a thought though, I don't know if it's the case.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Wed Dec 12, 2012 6:12 am

Well it's running on iOS in canvas2D... which is where the problem is, since it can't use webGL to let the GPU handle some of the load.

I have the sprites in game as a global object but they are on a layout that isn't accessed... Do I need to have it go to that layout first and then jump over to the main layout?

I think I was having worse results by having it destroy at start but remain in the main layout.

Do you think maybe creating the objects at start and then destroying them would load them while also removing them until I need them?
B
7
S
2
G
3
Posts: 28
Reputation: 2,260

Post » Wed Dec 12, 2012 9:44 am

Hmm... Maybe it's safari unloading the textures on it's own. Browsers have their own memory management.

Global means the object is not destroyed when switching layouts. You need to go to the layout it's on first, or create it in the layout instead. You'll probably still have the problem if you destroy all instances of it at any point. There must always be an instance of it somewhere, even if it's invisible, or you're going to have a pause when loading the textures when creating an instance again.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Wed Dec 12, 2012 2:20 pm

In the canvas 2D renderer it is not possible to manually manage memory like we do with WebGL - it's entirely down to the browser. So in this case it's a problem with Safari rather than Construct 2. To preserve memory, Safari probably does not load any textures until they are actually drawn, which means the first time they are created and start playing an animation it's loading a texture for every new frame that appears. It's difficult to work around this, because you'd need to render every frame of every sprite you want pre-loaded before the game starts.

I would strongly recommend you do not use 100-frame animations in the first place. This is the fastest way to exhaust limited device memory on mobile and make your game unplayable on weaker devices.
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Post » Wed Mar 27, 2013 11:00 pm

@Ashley - this is a slightly old thread, but I'm having trouble with this now, so I hope you don't mind the resurrection:

Would splitting a 100 frame animation into smaller chunks of animations within the same sprite help performance issues? Say, instead of 100 frames in one animation, doing 4, 25-frame animations (and then setting them to run one after the other).
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Thu Mar 28, 2013 12:34 am

All animations within a sprite are loaded when the sprite is loaded, so it would not help with this problem.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Post » Thu Mar 28, 2013 12:49 am

@wretchedshark the only thing to do is try and make the animation with events, or perhaps try to reduce the framerate.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,390

Post » Thu Mar 28, 2013 12:50 am

@Arima - Thank you! Are there any other possible workarounds?

If it's quite large I assume making it a global object would probably cause problems for weaker devices since it would never be destroyed (from layout to layout) right?

@sqiddster - thanks for the reply! Its for a project that is not mine, it's a gif to explain the "story" - given it's size I expected a delay (it's quite large and just over 100 frames) they are concerned about the delay, so I was looking for solutions.

The delay seems to happen every time whereas sound delays after first loading are no longer there, so it must be combination of the size and the browser loading it when it is first drawn.

Thanks again for the replies, I always like learning more about improving performance wretchedshark2013-03-28 01:14:28
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Thu Mar 28, 2013 1:44 pm

Note this thread is out of date; we implemented preloading in canvas 2D via a hack, so even canvas 2D browsers like Safari should preload images layout-by-layout without loading anything during the game. So I am doubtful image loading is still causing any issues you're having.

Splitting up animations will have no effect whatsoever; if a sprite object is on a layout, the preloader will load every animation frame for it. As I said earlier in the thread I still strongly recommend you don't use such long animations, since it can be extremely wasteful for devices with limited RAM, like mobiles. We get a lot of support requests from people with "broken" games, when all they've done is given the device more images than it can fit in memory.Ashley2013-03-28 13:44:49
Scirra Founder
B
357
S
214
G
72
Posts: 22,946
Reputation: 178,228

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Eisenhans, humanescape, Triforce and 6 guests