Sprite objects vs. instances

0 favourites
  • 6 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hi guys,

    First post here as I'm going through the system and coming up with ideas, best practices, and generally getting my head around choices when building games. As I primarily come from a programming background I tend to lean towards that for approach. So this begs the question of objects vs. instances.

    Obviously if I have 100 enemies in the game I'm going to spawn an instance through the system. However what about the Player? In many tutorials people are just adding a sprite to the game, calling it player and putting it on the board. Even though I have one player in the entire game I wonder is it better to create an instance (so I set all my dynamic properties like health, etc.) instead of using the sprite object?

    I realize the name object and instance here are Construct terms and don't necessarily adhere to an object and instance in programming languages but just wondering what the best approach here is (and if there is a performance hit between the two).

    Thanks!

  • I'm looking best practices like this thread too.

    I doubt we can compare the performance between 100 objects as sprites with different animations against one object with 100 instances with folder of different animations.

  • Joannesalfa I agree the comparison might be moot. I just see everyone using the sprite object as their player for example and wonder about the whole object vs. instance. Again, it might be negligible with only a few objects but 1000s of instances vs. 1000s of objects? Maybe something there.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Objects and instances are the same in Construct as in a programming language.When you add a sprite to a project you are adding a object type and one instance of the sprite to the layout. You can have as many sprite object types as you want but generally I find it easier to make the events for a lower amount of object types.

  • Objects and instances are the same in Construct as in a programming language.When you add a sprite to a project you are adding a object type and one instance of the sprite to the layout. You can have as many sprite object types as you want but generally I find it easier to make the events for a lower amount of object types.

    So if I read this correctly, objects in Construct are not classes like in a programming language and Construct instances are not like programming objects? When I create an object (through the Spawn object) I'm always creating a new object with it's own set of instance properties? So every object just has a unique set of instance properties but otherwise is an object?

    The manual instances have the properties, the objects do not, but I don't see how you create an instance at runtime (there's no Create instance action in the System but there is a Create object).

    To summarize if I had say a sprite defined as Enemy and an instance variable of Health on the Enemy if I spawn 1000 objects it's the same memory footprint (1 byte [Health] X 1000 items) as 1000 instances of Enemy (regardless of how they were created)

    Thanks for the clarification.

  • I read somewhere in the forums that having more sprite objects is more CPU intensive then having more instances of one sprite object. So having 1000 different sprite objects affects the memory usage more then having 1000 instances of one sprite object that is recopied and reused.

    Also I would think an object is equivalent to a class in programming. As for instances, well an instance is just the amount of copies you have for one particular sprite object. So lets say I created an object called "enemy", I can then have 10 instances of that sprite object by spawning/creating it 10 times on the map.

    You can also specifically choose an instance of a set of objects.

    Im not sure what you mean by manual instances, but objects do have properties as well.

    If you want to create an instance variable for an object at runtime you have to click on your sprite object then look to your left menu to where it shows "Instance Variables" and assign them from there.

    If you want to set a value to that particular instance variable you have assigned, then select the sprite object you assigned your instance variable to in the event sheet and use the "add actions" command to select your object and select the instance variable command.

    You can then set your values (such as 100) to those instance variables by creating an event, for example

    Event---> on start of layout,

            Action-------->Set "Hero" instance variable "health" to 100

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