How do I spawn objects onto another sprite

0 favourites
  • 5 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hello everyone.

    I have made a sidescrolling game with coconut trees and coconuts

    I want to randomly spawn the coconuts on to the trees that come in, and making them fall.

    They are already falling, but only because i have placed a "create object" off the coconut right on top of the place where the tree is coming.

    Now there is only 1 tree entering on the side, but i want to let in many trees, and then randomly spawn a coconut from any of the trees that come in.

    How do i put the code in, so that when a tree comes in, there is 1 coconut on a random tree that enters the layout?

  • Think the easiest way, is to just add several imagepoints to the tree where you want the coconuts to be. And then when you spawn it you just tell it to spawn it at a random imagepoint. Imagepoint(Int(Random(5)+1) and just change "5" so it matches the number of imagepoints you have added to the tree.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the response nimos.

    I have been trying to do it like u said, but i can not figure it out.

    Here is what i did :

    I have made 1 imagepoint at the scrolling tree and called it "Imagepoint1".

    When i go to the event sheet, and i want to create a coconut every 3 seconds i am letting it spawn on Layer 0 (that is where my game is)

    On X and Y i am placing the code u provided like so :

    X : GameBoom.ImagepointX(Int(Random(1)+1))

    Y : GameBoom.ImagepointY(Int(Random(1)+1))

    When i run the game i dont see any coconut spawning from the tree.

    Do i have the code implemented on a wrong way ?

    Thanks in advance!!

  • [quote:gfcvgytb]X : GameBoom.ImagepointX(Int(Random(1)+1))

    Y : GameBoom.ImagepointY(Int(Random(1)+1))

    You cant do this as it would give some weird results as it will randomize the imagepoint for both X and Y. You can use the set position to another object which will allow you to tell what imagepoint you want it to spawn on. Since all the imagepoints goes from 0 to (the amount you have added) and 0 being the original imagepoint. We exclude that by adding +1 to the int(random(2) +1).

    Here is an example of how to do it, it will spawn a tree now and then and add up to 3 coconuts to it. Its very basic so there might be coconuts overlapping the same imagepoints and so on. But you can fix that in the one you need.

  • Thanks for the help!

    This is a great way of pinning and making the coconuts fall.

    I really can use this for my game.

    Thanks again!

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