Spawning objects on top of random platforms

Get help using Construct 2

Post » Sat Oct 12, 2013 10:41 am

Hello Scirra community,

Newbie programmer here and I've been playing around with the auto-run platform template. so far so good.

I'm trying to generate random objects(coins) on the randomly generated platform. Problem is, the objects spawn even when there is no platform beneath them (groan)

Is there some function that says to 'only generate the objects when there's a platform'?

Thank you all for your time
B
3
Posts: 3
Reputation: 181

Post » Sat Oct 12, 2013 11:11 am

maybe event

Y = random(some Y position)
when spawning PLATFORM on Y position
also spawn COIN on Y position - 50 (so it will be above platform)
B
18
S
7
G
1
Posts: 783
Reputation: 4,247

Post » Sat Oct 12, 2013 11:25 am

Not a function exactly like that, but there are ways to check if there is a platform.

You could choose to create coins only when platforms are created and only in the same (relative) position of the platform.

An example:

make an instance variable for the platform (coins)

on platform created: set coins to floor(random(4))

add a subevent

sytem compare two values: platform.coins = 1 :
- create coin at platform.x, platform.y-25

and another

sytem compare two values: platform.coins = 2 :
- create coin at platform.x-(platform.width/4), platform.y-25
- create coin at platform.x+(platform.width/4), platform.y-25

and another

sytem compare two values: platform.coins = 3 :
- create coin at platform.x, platform.y-25
- create coin at platform.x-(platform.width/5), platform.y-25
- create coin at platform.x+(platform.width/5), platform.y-25

This way they are also evenly placed along the platform.
If coins is 0 no coins are created.

Ok, I got a bit carried away here, the code might be a bit difficult for a beginner, but the best option I think is creating the coins on creating the platform, that way you can place them within the platform width.




I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Oct 12, 2013 2:19 pm

Hey budds, thanks for the suggestions!

I'm trying them all (even the carried away bits) - so far a little of this and that seems to be doing the trick. I'll let you know how it turns out

Thanks again! great forum
B
3
Posts: 3
Reputation: 181


Return to How do I....?

Who is online

Users browsing this forum: Darknessed, matriax and 43 guests