How to set actor to spawn automatically in different locations? (endless game)

Kastex

  • Posts: 42
first of all, i started using stencyl about a year ago or so, but i haven't used it much so i'm still new and trying to learn. i want to make the kind of simple game where there is one small scene.  the player can move right and left and there are objects spawning from the top falling down to the player to kill the player if the player doesn't keep dodging them. the type of endless game. very similar to how the spikes fall in the ragdoll avalanche browser game series and other browser games that have the similar mechanic.

i made a game like this sometime last year, but the method i used to spawn the spikes was by using a stock particle behavior in stencyl forge. definitely not the task that behavior was meant to fulfill. it would be much more optimal to learn how to do what i need it to do.

what i think i need to do is to set the spikes actor to spawn at random locations with a y axis offset to make sure that they only spawn at the top of the screen.  since it's my first time this should be basic. i don't mind if the spikes either spawn at completely random locations at the top of the screen or only within a certain radius of the player. whichever is easier. it's also fine if all of the spikes fall at the same speed.

can someone help me with this?

JeffreyDriver

  • Posts: 1829
I did something very similar recently. See attached image.

It could be easily tweaked to spawn only at a certain distance from the player.

In my example I use gravity to make the blocks fall, but you could set velocity instead if you wanted some variation.
Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Kastex

  • Posts: 42
thanks. seems quite confusing. i guess it will take some time to get used to using these blocks.

JeffreyDriver

  • Posts: 1829
You won't need most of that. The main bit of code you want is in the 'do every 3 seconds' block. The code before that you can ignore.

The 'if' event immediately after the 'create' event switches the animation of the falling object and enables gravity. I added that so the player gets a bit of a warning rather than the object falling as soon as it was created.

The 'when updating' event simply checks if the object has fallen off screen and then kills it. This is for performance reasons so you don't end up with lots of actors off-screen.

Current Projects:
Retro Redux Compilation (NEW).
Retro Redux (untitled) (NEW).
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk