How do I know the instance type of families instance?

Get help using Construct 2

Post » Sun Jun 29, 2014 1:29 am

I'm creating object from a family randomly. How do I find out the instance type so that I can apply different behavior?

For example, a tree is spawned and it will scroll down vertically. Then, every now and then, an animal is spawned that will run across the screen. I would like to set the tree.X of tree to be 0, but the animal.X to a non-zero value.

Thanks.
B
7
Posts: 4
Reputation: 283

Post » Sun Jun 29, 2014 1:58 am

Why do you have the tree and the animal in the same family to begin with?
Events can still be added independantly from each other just as you described by putting "tree.x" this will not affect your animals in any way.
Only events added to the family will be applied to both the animal and the tree.
And if you must know, you could add an instance variable to both the tree and the animal and call it "test".
For the animal "test" will be 1 and for the tree "test" will be 0.
This way you can check the instance variable to see which instant it actually is.

I hope this helps you in the general direction you would like to go.
B
6
S
1
Posts: 73
Reputation: 571

Post » Sun Jun 29, 2014 2:20 am

Thanks for the pointers, rezagamertag.

Maybe I might have gotten the wrong concept. I grouped them as the "obstacle" family that the player need to avoid.

I'm creating an instance of the obstacle, rather than the object. A random object will be created - so could be tree or animal.
System: Every 3.0 seconds System: Create object obstacles on layer 1 at positionX, positionY

So, I am thinking of using the onCreate to check the object, then reset the position and set the velocity for Y if it's an animal.
B
7
Posts: 4
Reputation: 283

Post » Sun Jun 29, 2014 2:25 am

You can also use a local variable inside your spawn function and make it a random number between 0 and 1.
If it's a 0 you spawn a tree, if it's a 1 you spawn an animal.
You can make a random number by using "set variable" "round(random(0,1))"
B
6
S
1
Posts: 73
Reputation: 571

Post » Sun Jun 29, 2014 2:30 am

Ah, ok, thanks! That should work for my simple game :)
B
7
Posts: 4
Reputation: 283


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests