I have a sprite that you can move across the screen. I’m trying to figure out how to make a button pop up and say Try Again or something when the sprite falls off the bottom of the screen. My stage is set up horizontally not vertically. Also if possible I would like to have the game move to the next level once the sprite reaches the end of the level IE going off the right side of the screen. Any help would be appreciated.
Cheers,
Andrew [import]uid: 72845 topic_id: 13117 reply_id: 313117[/import]
You probably will need an “enterFrame” event that manages your game loop. In there you can test to see if your player’s y is greater than the display.contentHeight (meaning he’s moved off screen at the bottom) and if that condition is true, call a function to show your “Try again” button. Likewise, if the player’s X is greater than display.contentWidth, he’s moved off the screen to the right, and you can then call your next level.
[import]uid: 19626 topic_id: 13117 reply_id: 48161[/import]
Any chance on a code example? I’m still a newbie and just getting my feet wet with all of this.
Thanks for the response [import]uid: 72845 topic_id: 13117 reply_id: 49400[/import]
The other thing you could do is have some physics bodies located just off the bottom of the screen and just to the right of the level’s finish line. You could have collisions trigger the ‘try again’ and ‘level complete’ logic. [import]uid: 81026 topic_id: 13117 reply_id: 49405[/import]
Well I have a sprained wrist and I’m not going to be typing too much.
local function gameLoop(event)
-- reached the end level position?
if player.X \> (display.contentWidth - player.contentWidth) then
-- code here to go to next level
end
-- fell off the bottom of the screen
if player.y \> display.contentHeight then
-- code here to take away a life and regenerate at the starting pos
end
end
RunTime:addEventListener("enterFrame", gameLoop)
The physics way to do it would be to add two sensor objects one display.contentWidth wide, 1 pixel high off screen by a bit (perhaps player.contentHeight) and a sensor about the player size at the end of the level (like a door) that the player runs in to, then you can use physics collisions instead. [import]uid: 19626 topic_id: 13117 reply_id: 49488[/import]