How do I know the instance type of families instance?

0 favourites
  • 5 posts
From the Asset Store
Fully animated top down pit bull type dog game asset
  • 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.


  • 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.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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))"

  • Ah, ok, thanks! That should work for my simple game

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