How do I use sprites in right way?

0 favourites
  • 8 posts
From the Asset Store
Drift To Right
$6.75 USD
25% off
Awesome drifts on auto generate way,tap to steer right.
  • Hi, sorry for the noob question. I'm trying to do an adventure game and i'm using sprites with instance variable "name" to identify them in the XML file

    I think that probably i'm doing it the wrong way, if i understood well it would be better to use a single sprite and an animation with the name that will be used in XML in place of variable one. My question.. is really better to use a single sprite with multiple animations for different objects and, above all, what is the reason?

    Thanks in advance,m also for you patience, and sorry for my english!

  • In less words.. For items in an adventure game is better a single sprite with different animations for every object or is the same to use a different sprite for each one of them? If better to use one sprite, what is the reason? Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • In some (but not all) situations there are gains to be made in performance by limiting the total number of different sprites objects in your game, but there are also other good reasons for containing multiple objects on a single sprite, mainly by making your project a little more readable and simplifying the code requirements.

    There are a few factors to consider before determining what the best solution would be:

    1) I would tend to only include objects on the same sprite that appear on the same layout as you would otherwise be filling up your memory for each layout with unnecessary art assets.

    2) I would only include objects on the same sprite that have simple behaviours and use the same basic logic e.g. all inventory items, otherwise your code will become overly complex trying to differentiate between the objects when you could instead just refer directly to a specific sprite.

    3) If there were groups of objects that appeared on different layouts with similar behaviours, or objects with quite complex behaviours and multiple animations on the same layout, then I would prefer to put them on separate sprites and add them to a family so that I can still use the same code groups to control them.

    4) In certain circumstances I would use the individual frames on a single animation for different objects e.g. scenery objects, non-animated pick-ups. This also makes it quicker to import graphics as you can import a sprite strip to a single animation instead of individual frames to separate animations.

    5) It is much easier to perform actions like spawning random objects when they are on a single sprite: for example, if I had 10 pickups and wanted to spawn a random one then if the pickups were on separate sprite objects I would need to assign a random number to a variable to determine the pickup and then have a string of 10 conditions to spawn the correct one; if instead I had each pickup on a single frame or animation then I just spawn the sprite and pick a random frame or animation - 2 actions on 1 event as opposed to 10 conditions.

  • In some (but not all) situations there are gains to be made in performance by limiting the total number of different sprites objects in your game, but there are also other good reasons for containing multiple objects on a single sprite, mainly by making your project a little more readable and simplifying the code requirements.

    There are a few factors to consider before determining what the best solution would be:

    1) I would tend to only include objects on the same sprite that appear on the same layout as you would otherwise be filling up your memory for each layout with unnecessary art assets.

    2) I would only include objects on the same sprite that have simple behaviours and use the same basic logic e.g. all inventory items, otherwise your code will become overly complex trying to differentiate between the objects when you could instead just refer directly to a specific sprite.

    3) If there were groups of objects that appeared on different layouts with similar behaviours, or objects with quite complex behaviours and multiple animations on the same layout, then I would prefer to put them on separate sprites and add them to a family so that I can still use the same code groups to control them.

    4) In certain circumstances I would use the individual frames on a single animation for different objects e.g. scenery objects, non-animated pick-ups. This also makes it quicker to import graphics as you can import a sprite strip to a single animation instead of individual frames to separate animations.

    5) It is much easier to perform actions like spawning random objects when they are on a single sprite: for example, if I had 10 pickups and wanted to spawn a random one then if the pickups were on separate sprite objects I would need to assign a random number to a variable to determine the pickup and then have a string of 10 conditions to spawn the correct one; if instead I had each pickup on a single frame or animation then I just spawn the sprite and pick a random frame or animation - 2 actions on 1 event as opposed to 10 conditions.

    really thanks for your reply!!

    I thought the same about "organisation" of all my sprites, would be better. The only thing i would like to know if there can be a difference in performance using different sprites instead one.

  • I just cooked up this test:

    https://www.dropbox.com/s/lhrwuek3mudx0 ... .capx?dl=0

    It tests 3 different cases:

    1) 1 sprite, 10 frames on 1 animation

    2) 1 sprite, 10 animations with 1 frame

    3) 1 family, 10 sprites, 1 frame on 1 animation

    The sprites (or the family in case 3) have bullet and sine behaviours.

    The test spawns an instance every tick until the framerate dips below 50 fps. I compared the total number of sprites spawned before the test maxed out.

    Results: Cases 1 and 2 ran about the same, but case 3, using the family, spawned about 10% more instances, so it seems that in this test having multiple sprite objects with less animations/frames is more efficient than less sprite objects housing multiple animations.

    Bear in mind that I was hitting over 2600 sprites before it stopped in all three cases on my laptop, so for most purposes you're probably better off going the route that allows you to most efficiently organise your code and assets.

  • Wow, really interesting, thank you. I'm trying now to use only one sprite and see if is mor efficient in code (at least xml file will be shorter)

    Reallt thank you for your help

  • pcprice76 No worries, glad to be able to help out

  • .... so for most purposes you're probably better off going the route that allows you to most efficiently organise your code and assets.

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