Creating objects at run-time problem !!

0 favourites
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • 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.

    <center><img src="http://i44.tinypic.com/2lnkf90.jpg" border="0" /></center>

    Can anyone please help me understand this problem and sort it out ?

  • 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.

  • 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 ?

  • 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).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 ?

  • 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.

  • 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 ??

  • 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)

  • 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 ??

  • 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.

  • Oh.. That was the problem.. Was creating it on different layer.. Haha <img src="smileys/smiley4.gif" border="0" align="middle" /> ... My mistake...

  • ^_^    figured as much

    Great btw on that performance boost :)

    Will make it playable on a lot more devices.

  • Hello lennaert,

    Sorry to bug you again, but that crashing issue is appearing again. I have inserted all my images in the loader screen and destroying them on the 'On start of layout'. But still, my game is crashing. I have 15 images with 1920x1080p resolution. What else can I do ??

  • 15 x 1920 x 1080 x 4 = 124416000 bytes = 124416 kilobytes = 124.4 Megabytes

    and that is if they aren't transfered to a 2x2 ratio in which case it would be:

    15 x 2048 x 2048 x 4 = 251.7 Megabytes

    It might be a bit much loading them all at the same time.

    Try putting them in a layout that isn't loaded in it's entirety or find a way to reduce the image size, would be my advice.

  • They are converted to 2048X2048 sprite. Some of them are animation too (frames of page turning).

    I am currently implementing what you stated above. Will tell you result soon.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)