Page 1 of 1

How to set created object Y position in sets of 50 pixels?

PostPosted: Thu Mar 17, 2016 3:46 pm
by SteveKane
I've got a block thats created every second, and have it randomise the Y position everytime it's created. I know how to randomise that block, i've got that working fine but i wanted so that when it randomises, it does it in sets of 50 pixels (hope that made sense).

So if my layout height is 300, how do i get my created block Y position to appear randomly in either 0, 50, 100, 150 etc. rather than just any random number between 0,300?

I hope I've worded this correctly so it's easy to understand what i'm asking, hope seomeone can help.

Thanks.

Re: How to set created object Y position in sets of 50 pixel

PostPosted: Thu Mar 17, 2016 4:07 pm
by broknecho
Something like this?

1- Divide your height by your desired width: 300 / 50 = 6
2- floor(random(6)) = your random location
3- your Y value = 50 * random from step 2

Example:
300 / 50 = 6
floor(random(6)) = 2
50 * 2 = 100 <--- Answer

Have fun!

Re: How to set created object Y position in sets of 50 pixel

PostPosted: Fri Mar 18, 2016 11:56 am
by SteveKane
@broknecho Thanks for the reply, but thats just got me confused :)

How would i input this into my events?

Re: How to set created object Y position in sets of 50 pixel

PostPosted: Fri Mar 18, 2016 12:53 pm
by 0Hayes
Think of it more like a grid. What your randomizing is a chosen cell in that grid. For example, randomize a round number from 0-10 then x it by 50. It would look something like this round(random(10))*50. That's if my maths is correct anyway.

Re: How to set created object Y position in sets of 50 pixel

PostPosted: Fri Mar 18, 2016 2:16 pm
by alextro

Re: How to set created object Y position in sets of 50 pixel

PostPosted: Fri Mar 18, 2016 2:40 pm
by broknecho
Sorry about that @SteveKane! I thought you were more just looking for the pseudo code or math to do it.

@alextro 's capx works good! Here's a screenshot of their solution on the the math there:

Image

That capx creates that green sprite on a multiple of 50 in the X axis along the top of the screen, Guitar hero-esque :)

Re: How to set created object Y position in sets of 50 pixel

PostPosted: Fri Mar 18, 2016 4:34 pm
by SteveKane
@broknecho @alextro @0Hayes Thanks for the replies, really helped me out. Appriciate it :)