Performance: Spawn or visibillity or animation.

0 favourites
  • 14 posts
From the Asset Store
3 pixel charaters with over 8 animations each + animations with a gun
  • Hello guys,

    Working on a game and I have 3 options to do something.

    1 Use spawn and destroy sprite (72 different sprites)

    2 Set visibility on and off (72 different sprites)

    3 Use animation (12 different sprites, each 6 animations.)

    What will be the best option regarding performance?

    Only found one topic about it, but the answer wasn't clear to me, so please enlighten me

    Thanks!

    Daan

  • No one knows???

  • Stil no one?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For me, the best way to know is to preview it in debug mode, then click profile to your right to see cpu utilisation. FPS is also a good indicator to evaluate the performance.

  • For me, the best way to know is to preview it in debug mode, then click profile to your right to see cpu utilisation. FPS is also a good indicator to evaluate the performance.

    Thanks for the reply!

    I know that is probably the best way to do it....the problem is that 72 sprites in 3 different ways is a lot of coding for me. It will take me a couple of days to check it. I kinda thought that someone knew what would be better. Currently i got my the 72 sprites in the screen (and turn visibillity off and on) and the memory usage is very high(90). That is my biggest concern. Would the other methods: animition or..... load them on a not used layout and spawn and destroy, lower the memory usage?

  • I'm not sure on what you are trying to achieve here, I can't really see how animating sprites can be replaced by spawning/deleting.

    My thoughts:

    1- Spawn/Destroy, if you are going to spawn 72 objects in 1 frame, that may cause a significant fps drop depending on the objects.

    2- Having 72 sprites on the screen is quite a bit of sprites, if you have collisions or another interaction between them, could be a problem.

    3- Animating? I don't really get how it can solve your problem, do you mean moving them out of sight?

    It's hard to tell you the best way without further details on the project, maybe a little more explaining or some screenshots may help.

  • I'm not sure on what you are trying to achieve here, I can't really see how animating sprites can be replaced by spawning/deleting.

    My thoughts:

    1- Spawn/Destroy, if you are going to spawn 72 objects in 1 frame, that may cause a significant fps drop depending on the objects.

    2- Having 72 sprites on the screen is quite a bit of sprites, if you have collisions or another interaction between them, could be a problem.

    3- Animating? I don't really get how it can solve your problem, do you mean moving them out of sight?

    It's hard to tell you the best way without further details on the project, maybe a little more explaining or some screenshots may help.

    Thanks for the help!

    About the game:

    It is a point and click game so collisions are already enabled. 12 different objects are showing that you each can upgrade 6 times. So in total there are 72 different objects but only 12 are showed at the same time. That is the reason there are 3 ways to do the upgrading.

    animation: When object is upgrade(simple click) go the next frame of the animation.

    Spawn and destroy: 72 objects on a different unused layout. At start of game spawn the first 12 objects. When you upgrade(simple click) it destroys 1 object and spawns another at the same position.

    Visibility: 72 objects on the current layout. Turn visibility off for 60 objects so only 12 are visibile. When you upgrade(simple click) it will turn visibility of 1 object off and will turn it of 1 object back on.

    See there are 3 ways to do achieve the same result.

    The problem is there is no information about which one could be better used. It's a shame because this will probably help so many people! Especially when you work with things like upgrades.

    So what do you think?

  • ddaan9

    Here is how I would assess the options:-

    animation: uses more memory as all 72 frames are loaded (I think), probably no fps spike on changing frame

    spawn/destroy: uses less memory as only 12 images loaded, may cause fps spike when spawning (depending on size of images)

    invisibility: uses more memory as all 72 images loaded, requires extra checks for collision/clicks/etc.

    If the images are small enough to not impact memory too much (e.g. are 128x128 or less), I'd personally choose animation and keep the objects upgrades as frames of the object, otherwise:

    If memory is an issue, use spawn/destroy.

    If fps is an issue, use animation.

  • ddaan9

    Here is how I would assess the options:-

    animation: uses more memory as all 72 frames are loaded (I think), probably no fps spike on changing frame

    spawn/destroy: uses less memory as only 12 images loaded, may cause fps spike when spawning (depending on size of images)

    invisibility: uses more memory as all 72 images loaded, requires extra checks for collision/clicks/etc.

    If the images are small enough to not impact memory too much (e.g. are 128x128 or less), I'd personally choose animation and keep the objects upgrades as frames of the object, otherwise:

    If memory is an issue, use spawn/destroy.

    If fps is an issue, use animation.

    Awsome reply!

    I already was thinking to use spawn and destroy. Because only one upgrade is done at the time i think the fps spike will not effect the game huge and memory usage is my problem.

    Thanks for the reply!

    And guys if you think otherwise or think the same, post it here. This will help a lot of new users!

  • Spawn & destroy is probably not a good idea, as it uses memory AND CPU in the end.

    If memory is an issue read about this blog article and make sure you're not overdoing it.

    Also, you talk about 72 different objects, but in the end you could have 12 different sprites containing each 6 different animations. This maybe won't have impact on the memory usage, but at least it sounds like a better programming practice.

    Posting your capx would probably be the best way to telling you definitely what's going wrong.

    But I suspect 72 frames causing memory issues just means you are using too big textures as explained in the blog article.

  • Visibility wouldn't be an option for me at all.

    About spawning, the images are all loaded up anyway, you need to leave one instance of each object type at the layout for it to be able to spawn later, could possibly be an option but not a good practice, imagine controlling 72 sprites, can easily become a mess.

    My choice would definitely be animation, it's easier to control and probably the best practice, you can also create a family for all the upgradable objects and use one logic for them all, something like: On Click 'Upgradable' > set frame to currentFrame+1

  • When spawning to avoid spikes use fade in top appear more smoothly and maybe don't spawn them all at the same time.

  • Tried it with spawn and destroy....memory usage went from (in debug mode) 84,6mb to 30-40mb. Cpu lightly increases(1-2%) but for a point and click game

    spawn and destroy definitely works great.

  • Use a variable that toggles (enables/disables) visibility & collision then reset animation and location/position

    • Much more work but it'll save memory. Make sure all your textures are power of two & limit the amount of collision points where possible.

    -Measure your fps and if your struggling with all that then see what sprites are taking up the most memory and make adjustments accordingly.

    • Also try grouping the sprites so you don't have to list conditions & actions for each individual one
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)