How do I spawn objects onto another sprite

Just started using Construct 2? Post your questions here

Post » Sun Apr 20, 2014 12:44 pm

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?
B
6
S
1
Posts: 8
Reputation: 416

Post » Sun Apr 20, 2014 1:35 pm

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Apr 27, 2014 9:23 am

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!!
B
6
S
1
Posts: 8
Reputation: 416

Post » Sun Apr 27, 2014 1:10 pm

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.

https://dl.dropboxusercontent.com/u/109921357/Coconuts/index.html
You do not have the required permissions to view the files attached to this post.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sun Apr 27, 2014 3:24 pm

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!
B
6
S
1
Posts: 8
Reputation: 416


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest