I'm wondering what is the best way to have platforms move

Hi what I’m trying to do is make a platform game in where a person is running on an endless moving platforms. Basically you jump on the platform.

So here’s the code for for just only moving platforms vertically only

[code]local baseline = 280

local platform = display.newRect(0, 0,10, 100)
platform.x = 400
platform.y = baseline - 40
platform.rotation = 90

local platform2 = display.newRect(0, 0,10, 100)
platform2.x = 400
platform2.y = baseline - 30
platform2.rotation = 90

local tPrevious = system.getTimer()
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time

local xOffset = ( 0.5 * tDelta )

platform.x = platform.x - xOffset
platform2.x = platform2.x - xOffset

if (platform.x + platform.contentWidth) < 0 then
platform:translate( 500 * 1, 0)
platform.y = 30 + math.random(460)
end
if (platform2.x + platform2.contentWidth) < 0 then
platform2:translate( 520 * 1, 0)
platform2.y = 30 + math.random(460)
end
end
Runtime:addEventListener( “enterFrame”, move )[/code]

So I’ve been wondering is this code correct if not can you provide me the right way of making platforms move vertically and spawn randomly.

Thanks :slight_smile: [import]uid: 17058 topic_id: 19650 reply_id: 319650[/import]

“Vertically” means up/down, while “horizontally” means left/right.

There are multiple ways of doing this, although I quite like this as it’s “recycling” the platforms - the other way would be spawning platforms each time and then removing them once they were off screen.

That said, you may want to slow these down a little - that looks like it will run pretty fast :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 19650 reply_id: 75941[/import]