Access Specific Instances of Sprites?

0 favourites
  • 6 posts
From the Asset Store
Build your map with these isometric objects and terrains
  • For a while now I've been wondering how to access a specific instance of a sprite. I am aware of IIDs and UIDs but it is not clearly spelled out on how to access them through those methods.

    Some Context:

    I am currently making a SNAKE clone and I have completed everything except for adding new body segments when the fruit is eaten. I've created SNAKE in pure Java before, so I'm well aware of what I need to do in a broader sense. However, I've been diving through the Construct 2 UI and I can't find anything about accessing sprites in a one-at-a-time fashion or retrieving sprites from a specific variable. This is aggravating me as if I knew how to do this I would have no problem whatsoever. However, as I don't know I need to ask for help on these forums and see if anything comes up.

  • It's something I struggled with at first as well.

    Did you read the section in the manual about how Events work? That might be the best place to start.

    I'm not exactly sure what you are asking in your example, can you be a little more clear there? What part of the snake clone are you not getting in terms of the UI?

  • Admittedly, I should have left out the "UI" part as my problem has nothing particular to do with it.

    So let me attempt to be a bit more clear; in more general game programming, everything in a game is an object. A brick in Super Mario Bros. is an object of the game, along with a coin, a goomba, and Mario himself. However, there can be multiple instances of those objects. You don't see a Super Mario Bros. level that just has one brick or just one goomba in it. What I want to do is access a specific instance of an object and perform Event Sheet-based operations solely on that single instance. From what I have experienced using Construct 2, the suite only allows performing Event Sheet-based operations on entire objects rather than instances of those objects.

  • Every instance of a sprite have an unique UID.

    To access a specific instance, you can use the event "pick instance with UID"

  • You can have an instance variable called 'id' and when you create each body segment you create it with an 'id' equal to the current number of apples you have eaten.

    This way the first body part is id=1 and so on.

    Now you can select the instance by its id, or make a loop to cycle through them quickly.

    Alternatively, you can select objects by instance id from the System object (not sure how this numbering work though)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Construct2 allows to pick specific instances of the object type through the conditions of the events.

    Read again the manual article mentioned previously about how events work in C2.

    For the issue your mentioning in Snake, I did something similar in my tutorial Asteroid in less than 100 events where I needed "recursion" in picking different instances of a same object type.

    As for more informations on picking, check the how do I FAQ at the section "Picking/selecting instance(s)". The use of UID and IID is explained clearly across several topics.

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