Access Specific Instances of Sprites?

Get help using Construct 2

Post » Sat May 11, 2013 12:36 am

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.
B
3
Posts: 2
Reputation: 604

Post » Sat May 11, 2013 12:41 am

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?

B
94
S
29
G
11
Posts: 1,545
Reputation: 20,993

Post » Sat May 11, 2013 9:32 pm

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.
B
3
Posts: 2
Reputation: 604

Post » Sat May 11, 2013 9:42 pm

Every instance of a sprite have an unique UID.
To access a specific instance, you can use the event "pick instance with UID"
B
12
S
3
G
4
Posts: 62
Reputation: 3,408

Post » Sat May 11, 2013 10:35 pm

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)
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Sat May 11, 2013 10:57 pm

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.Kyatric2013-05-11 22:59:55
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound and 26 guests