Creating objects at run-time problem !!

Get help using Construct 2

Post » Wed Dec 25, 2013 9:02 am

Hello Everyone.

I am creating a game in which lots of images are used. After the game completed, I found out that the memory usage is very high (290MB) and because of this, the game was crashing on mobile devices. (I had inserted all images on the same layer and making visible/invisible as per need). So I deleted all images from screen and instead, written code for creating/destroying creating them as per need. (I didn't deleted them from project, just from screen). But when i debug the game, I am getting this error.



Can anyone please help me understand this problem and sort it out ?
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Wed Dec 25, 2013 9:29 am

It is (still!) a quirk of the engine (Ashley response) and unfortunately is stating the answer.

The best thing is to either have a separate layer with all graphics on (or per level even) or have the instance on the Layout, offscreen, and Destroy on Start.zenox982013-12-25 09:30:31
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,385
Reputation: 58,452

Post » Wed Dec 25, 2013 9:37 am

I got your point. But I have a doubt. Though in different layout, wont it still take high memory use before destroying them and crash the game again ?
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Wed Dec 25, 2013 10:13 am

If you have your object on a dedicted objects layout, then there is no need to destroy them.

Yes it gets loaded with your project, but no more then on any other layout.

If you have it on an objects layout, and your running your game on another layout, then there is no need to estroy it.

You can simply spawn or create a new object and it will get its details from the object on the object layout (where you might have given it instance variables for example, or set dimensions. Would you have not placed an object on a layout, these features will lack).
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Wed Dec 25, 2013 10:22 am

In short, somehow (anyhow), one need to put an object on (any) layout at least once to get its instance reference, right ??

One question, does loading of one layout automatically destroys the objects of previous layout ?
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Wed Dec 25, 2013 10:26 am

Yes, an object from your project tree needs to "exist" on one of your layouts.

Awnser:
Nope, all object on layouts will remain unless your events manipulates them.lennaert2013-12-25 10:27:14
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Wed Dec 25, 2013 10:38 am

Thanx !! That was truly a very helpful post.
Coming back to my problem, now all I can do is to keep my objects in different layout and destroy them on other (or same) layout. so their reference can be taken later. Is there any alternative to this ??
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Wed Dec 25, 2013 10:49 am

Objects on the dedicated objects layout do no need to get destroyed, in fact, you shouldnt.

On the other layouts, remove the instances in cs2.

And then, when you need to have one of the objects which are in the objects layout on any other layout, simply spawn or create a new version of the given object on the required layout, leaving the object on the objects layout in tact.

You should keep those objects there at all time, throughout your game.

after you created or spawned your object on another layout and have no more need for it, destroy that object in your layout (not on the objects layout)

lennaert2013-12-25 10:50:04
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Post » Wed Dec 25, 2013 11:13 am

Thanx for the tip. I have already implemented these tricks, and all working fine now. I reduced the memory use from 290MB to mere 24MB. But I am facing one other problem.
The image position is not proper. I gave them the same position as they were suppose to, but they are not appearing properly there. Any idea why (or how) this is happening ??
B
6
S
2
G
1
Posts: 77
Reputation: 708

Post » Wed Dec 25, 2013 11:19 am

Did you create/spawn them on the correct layer ?

If you spawn them on the wrong layer with a different scaling, then it will be out of place.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,567

Next

Return to How do I....?

Who is online

Users browsing this forum: jorgmaquoi, Lancifer, Yahoo [Bot] and 13 guests