Preloading sprites into Video Memory issues

Discussion and feedback on Construct 2

Post » Tue Jul 15, 2014 1:52 pm

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,423
Reputation: 194,560

Post » Wed Jul 16, 2014 12:59 am

MaorKeshet wrote:
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....


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

Post » Wed Jul 16, 2014 1:06 am

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

Post » Wed Jul 16, 2014 7:32 am

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

Post » Wed Jul 16, 2014 7:44 am

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

Post » Wed Jul 16, 2014 8:36 am

MaorKeshet wrote:
Ashley wrote: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.


As far as I am aware, if the instance is placed on the layout view, it will exist on start of layout, and so will be loaded into memory for the whole duration of the layout, same if you create the object at runtime.

If you do not need an object to be loaded into memory, just don t create it and by extension do not place it inside the layout view, as for using a unique sprite with a lot of animation, I am pretty sure this is the exact reason why you should not use that unless the number of animation is not high.
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 » Wed Jul 16, 2014 8:36 am

Sorry to hijack your thread, but I have a small question: I have an unused layout, which contains all assets that are spawned in other layouts.

Is this a good practice, or should I place all the objects in the layout where they are spawn during gameplay?
Image
B
96
S
36
G
17
Posts: 351
Reputation: 15,903

Post » Wed Jul 16, 2014 10:47 am

MaorKeshet wrote: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???

No: the runtime treats separately objects which are placed in the layout, and objects that are not placed in the layout but created at runtime. If you destroy the last of an object that was placed in the layout, it is still not unloaded until the end of the layout. If you destroy the last of an object that was not placed in the layout, it will unload it.
Scirra Founder
B
397
S
236
G
88
Posts: 24,423
Reputation: 194,560

Post » Wed Jul 16, 2014 12:31 pm

@Ashley - Thanks for clarifying this issue. Makes perfect sense :)

@Aphrodite - I do not use multiple animations in one sprite. On my setup each of these heavy animations is a separate object , I never need more than one animation at the end of layout so no need for multiple animation load.
B
12
S
3
Posts: 104
Reputation: 1,655

Post » Fri Nov 07, 2014 4:06 pm

Ashley wrote:No: the runtime treats separately objects which are placed in the layout, and objects that are not placed in the layout but created at runtime. If you destroy the last of an object that was placed in the layout, it is still not unloaded until the end of the layout. If you destroy the last of an object that was not placed in the layout, it will unload it.


hmm, did something change in releases since this post?
In r187 I have two layouts. layout1 is completely empty, layout2 have a sprite with few frames.
In runtime on layout1 when I click mouse button it creates Sprite from layout2, at this point image memory goes up to ~28mb. But if I then destroy this object image memory stays at ~28mb.

It looks like this "If you destroy the last of an object that was not placed in the layout, it will unload it" is not working, because after destroying last instance of the object that was initially not placed on layout1 it will keep it in memory instead of unloading it.

Edit: Switching between layout1 and layout2 shows image memory correctly. ~3mb for layout1 and ~28mb for layout 2. So i would assume that C2 is not unloading objects from memory even if you destroy the last instance of object from other layout.
ImageImageImageImage
B
157
S
66
G
42
Posts: 2,603
Reputation: 35,343

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 9 guests