Generate backgrounds or obstacles?!

My game so far has an endless parallax scrolling background and I have obstacles in the game and I wnat these obstacles to remove themselves and generate new ones in different places. I am making a game like jet pack joyride I need the obstacles to be random because I don’t want them in the same place every 10 seconds. Thanks!

Hey,

Take a look at http://docs.coronalabs.com/api/library/math/random.html and http://docs.coronalabs.com/api/library/math/randomseed.html (to ensure that your random values returned are erm… random)

I’ve not played Jetpack Joyride, to be honest, but ideally if you want to generate random positioning of objects on the screen then you need to make use of randomising the x and y values of the objects.  So, assuming that your objects can be placed anywhere on screen, you can have something like:

local _W = display.contentWidth

local _H = display.contentHeight

local mRand = math.random

math.randomseed(os.time())

– within a loop/timer/enterFrame…etc…

    obj.x = mRand(obj.width, _W-obj.width) – using width of object ensures that it doesn’t appear half out the screen

    obj.y = mRand(obj.height, _H-obj.height) – ditto

This is an example at it’s most basic… but should hopefully give you some idea dude.

Rich

Hey,

Take a look at http://docs.coronalabs.com/api/library/math/random.html and http://docs.coronalabs.com/api/library/math/randomseed.html (to ensure that your random values returned are erm… random)

I’ve not played Jetpack Joyride, to be honest, but ideally if you want to generate random positioning of objects on the screen then you need to make use of randomising the x and y values of the objects.  So, assuming that your objects can be placed anywhere on screen, you can have something like:

local _W = display.contentWidth

local _H = display.contentHeight

local mRand = math.random

math.randomseed(os.time())

– within a loop/timer/enterFrame…etc…

    obj.x = mRand(obj.width, _W-obj.width) – using width of object ensures that it doesn’t appear half out the screen

    obj.y = mRand(obj.height, _H-obj.height) – ditto

This is an example at it’s most basic… but should hopefully give you some idea dude.

Rich