Spawning Enemies and Automatically placing objects

My first question is, how would I go about spawning enemies in a game like Doodle Jump, where my character is moving upwards and would have to avoid these enemies.

My second question is, how would I go about taking my background image and replicate itself on top of the original, and so on, so I would have an infinite scrolling background, rather than placing each one manually. Is there a better way to create an infinite scrolling background?

All help is appreciated! [import]uid: 7116 topic_id: 6471 reply_id: 306471[/import]

Anybody? [import]uid: 7116 topic_id: 6471 reply_id: 22431[/import]

Anybody?? [import]uid: 7116 topic_id: 6471 reply_id: 22561[/import]

Here’ an example to help with your first problem [lua]local function randomStuff()

boosters.x = math.random( 960 )
boosters.y = 300 - math.random( 5000 )
boosters1.x = math.random( 960 )
boosters1.y = 300 - math.random( 5000 )
boosters2.x = math.random( 960 )
boosters2.y = 300 - math.random( 5000 )
boosters3.x = math.random( 960 )

end
timer.performWithDelay( 0, randomStuff, 1 )[/lua]

That is not all you will need for a good effect but, should help you for a start. For your second question if your background is static then you can just say bg.y = character.y however if your bg is meant to change as your character progresses what I did is made the image in photoshop and then cut it into smaller pieces and created some functions like these, [lua]local function controlBG1()
if ship.y > -240 then
local bg1 = display.newImageRect(“bg1.png”,960,500)
game:insert(bg1)
bg1.x = 0; bg1.y = 240
bg1:toBack()
elseif ship.y < -240 then
game:remove(bg1)
end
end

Runtime:addEventListener( “enterFrame”, controlBG1 )

local function controlBG2()
if ship.y < 338 then
local bg2 = display.newImageRect(“bg2.png”,960,500)
game:insert(bg2)
bg2.x = 0; bg2.y = -260
bg2:toBack()

elseif ship.y > 338 then
game:remove(bg2)
end
end

Runtime:addEventListener( “enterFrame”, controlBG2 )[/lua]

Keep in mind the texture memory on mobile devices is quite limited so youre going to have to optimize your background so it’s not to large otherwise it will cause your game to lag. Hope I helped [import]uid: 11465 topic_id: 6471 reply_id: 22606[/import]

Thanks so much! I’ll make sure to try this when I get home! [import]uid: 7116 topic_id: 6471 reply_id: 22694[/import]

This is an improvement I made to the first example in my game [lua]local function randomStuff()

boosters.x = math.random( 960 )
boosters.y = 300 - math.random( character.y,character.y+5000 )
boosters1.x = math.random( 960 )
boosters1.y = 300 - math.random( character.y,character.y+5000 )
boosters2.x = math.random( 960 )
boosters2.y = 300 - math.random( character.y,character.y+5000 )
boosters3.x = math.random( 960 )

end

timer.performWithDelay( 7000, randomStuff, 0 )
timer.performWithDelay( 0, randomStuff, 1 )[/lua] I don’t know if that applies to you but now it will rerun that function every seconds replacing the objects at a point ahead of your character. [import]uid: 11465 topic_id: 6471 reply_id: 22764[/import]