-- declare variables and libraries local physics = require "physics" display.setStatusBar( display.HiddenStatusBar ) --launch initial stuff physics.start(); physics.setGravity(-1,0); score = 0; --run title screen stuff --display start button --add a listener for the button local startButton = display.newImage("playbuttonmaster.png") startButton.x = 130; startButton.y = 565 transition.to( startButton, { time=200, delay=200, x=130, y=365 } ) checkBounds = function ( event) if (player.y < 0) then player.y = 0; end if (player.y > 480) then player.y = 480; end if(player.x > 320) then player.x = 320; end if(player.x < 0) then player.x = 0; end end function startButton:tap( event ) self:removeSelf(); --have the button listener create the game objects, remove the button, and add new listeners Runtime:addEventListener("enterFrame", checkBounds) Runtime:addEventListener("touch", handleTouch) --Runtime:addEventListener( "enterFrame", runMain ) player = display.newImage("player.png") physics.addBody(player, {density = .5, friction = .3, bounce = .2, }) player.bodyType = "dynamic" local type = player.bodyType player.id = "player" player.x = 100; player.y = 100; end --add a listener for the button startButton:addEventListener( "tap", startButton ) -- ENTERFRAME LISTENERS ----------------------- local moveLeft = function( event ) player:applyForce( .75, -1, player.x, player.y ) end local moveRight = function( event ) player:applyForce( .75, 1, player.x, player.y ) end function handleTouch( event ) print(event.phase); local phase = event.phase; if (phase == "began") then if (event.y < 240) then Runtime:addEventListener( "enterFrame", moveLeft ) end if (event.y > 240) then Runtime:addEventListener( "enterFrame", moveRight ) end end if (event.phase == "ended") then if (event.y < 240) then Runtime:removeEventListener( "enterFrame", moveLeft ) end if (event.y > 240) then Runtime:removeEventListener( "enterFrame", moveRight ) end end end