Spawning objects on top of random platforms

0 favourites
  • 4 posts
From the Asset Store
A pack of 76 platform designs for a platformer game with a mushroom/jungle theme
  • 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

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

  • Try Construct 3

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

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

  • 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

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