object load into memory

Discussion and feedback on Construct 2

Post » Tue Oct 13, 2015 3:49 pm

I have a number of sprite objects in my game that have about 30-40 frames.

Sprite1 (40 frames) 300k
Sprite2 (35 frames) 240k
Sprite3 (30 frames) 200k
Sprite4 (30 frames) 200k
Sprite5 (30 frames) 200k

Each of my levels only uses 1 type of sprite object in the layout. However, having those other sprites in the layout and destroying them on start up isn't enough, I believe they are still loaded into memory. I want to avoid this and save as much memory as possible.

Do I need to delete the instance in the C2 editor? (when you delete the last instance of an object in the layout and it pops up and tells you your object still exists) or should I make different layouts for each sprite type? I'd rather not make different layouts! Since I'd have to copy any changes to the HUD or pause menu...

EDIT: I tried deleting the last instance.. that doesn't work! what if I had the objects in a dummy layout? that way I don't need to destroy them all the time, and they are only created if I need them? I think there is a bit of jank when loading though. Maybe I can wait for the objects to be loaded since they are loaded OnStartOf Layout?
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Wed Oct 14, 2015 10:52 am

See memory usage in the manual. If there are no instances of an object in the layout view, its images won't be loaded at the start of layout.
Scirra Founder
B
397
S
236
G
88
Posts: 24,422
Reputation: 194,558

Post » Wed Oct 14, 2015 4:54 pm

@jobel
Many of us long term developers do indeed use a dummy layout. Only primary level objects are ever kept on the layout of use. If there is any possibility an object is NOT going to be used on every layout. Then just use a dummy. This tip always comes up whenever a "Best Practices" thread comes up.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,028

Post » Wed Oct 14, 2015 5:24 pm

@jayderyu thanks that seems to be the way to go... do you ever experience any jank when creating an object not in the layout?

I tried it and I can't tell without a lot more in-depth testing. All my loading is done OnStartOfLayout.. I have global variables that determine what kind of sprites the layout will use.. theoretically I could wait to start the level after any jank, but I'd rather not add more transition time between layouts.
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Wed Oct 28, 2015 11:37 pm

@jayderyu This now all seems moot looking into NW.js (which I'm using). It seems to cache each layout in memory negating any benefit from having a dummy layout.
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Thu Oct 29, 2015 12:44 am

Yup, it certainly does cache everything you've used on your layouts. So despite "per layout" design of C2, the 3rd party wrappers (Chromium) pretty much load everything and holds it in memory as a cache despite C2's active layout having functional garbage collection.

I didn't even realize that until I investigated it further after Klang's developer mentioned 4GB of memory usage crashing 32 bit OS.

Because of this, you can forget about making bigger games for mobiles with C2, even if mobile hardware can handle the logic & GPU power is enough, most devices have 1GB memory only, which they have to share with the OS & background apps.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 14 guests