Multiple instances of a given sprite

For questions about using Classic.

Post » Sun Oct 24, 2010 11:56 am

Is there a way to reference each instance of a given sprite? I wish to create an array for each instance of an enemy sprite, but I see no way to do this.
B
2
G
2
Posts: 24
Reputation: 698

Post » Sun Oct 24, 2010 2:02 pm

You can pick via a private variable, but referencing multiple instances in your actions is a bit tricky.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun Oct 24, 2010 2:23 pm

Could you explain this in more detail? I was thinking of perhaps using a custom behavior, but I have no idea where to start making a behavior...
B
2
G
2
Posts: 24
Reputation: 698

Post » Sun Oct 24, 2010 2:49 pm

Maybe I didn't understood you right, but you can use different Z in Array object for each enemy. For ex. Enemy's sprite UID = 1 array Z = 1. If I'm wrong see my sig)
B
19
S
6
G
4
Posts: 171
Reputation: 2,507

Post » Sun Oct 24, 2010 3:25 pm

[quote="aCuria":3gm6vjvv]Could you explain this in more detail? I was thinking of perhaps using a custom behavior, but I have no idea where to start making a behavior...[/quote:3gm6vjvv]

To pick an instance simply add a private variable and assign each instance a different value IE:
sprite.privatevariable('a')= 1, sprite.privatevariable('a')= 2. You can assign the values in the editor, or on creation of the instance. Then you just compare the private variable to pick that instance.
Thats the easy part.
The hard part is when you want to use more than one instance... behaviors aren't built to pick an instance via a pv.
However, you can create a custom behavior using some of the built in expressions.
[url:3gm6vjvv]http://www.scirra.com/forum/viewtopic.php?f=3&t=7350&p=57411&hilit=chain+python#p57411[/url:3gm6vjvv]
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Oct 25, 2010 7:23 am

I dont entirely understand what you are trying to say there, but I did look at the link provided and the cap files in that thread.

The method wont work for me because the object (key) has more than one state (used and un-used animation, private variable). I need to ensure that the right array is linked to the right key.

In the chain example, there was no difference between the different links of the chain, hence the method used there worked. As long as one of any link appears in each location, it works out fine.
B
2
G
2
Posts: 24
Reputation: 698

Post » Tue Oct 26, 2010 7:01 am

Here's an example:
[url:2vn0d8zc]http://dl.dropbox.com/u/5426011/examples2/snakes.cap[/url:2vn0d8zc]
Made in 0.99.96

The sprites have two variables "group" and "num":
"group" can be thought of as the array number the sprite is part of.
"num" can be thought of as the key or index in the array.

So for example to select the third sprite in group (or array) #1 two conditions are needed:

+ Sprite: Value 'group' Equal to 1
+ Sprite: Value 'num' Equal to 3


Is that helpful?
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests