I am using the Director Class to set up my game. I have a basic skeleton set up and a button that when pressed brings you to this gameplay screen, and a back button to bring you back to the main menu. This code below works just fine, with building images set up to scroll down the screen. Once I add the Runtime event listener, the app just will not work. When I press the back button the screen just goes black and nothing happens.
I have been pouring over the events and listeners Doc’s for awhile and cant seem to figure out whats going on, but I assume it is something to do with the Runtime being mixed with the backbutton Object listener. Anyone have any insight into this issue? Thanks a lot in advance!!
[code]
module(…, package.seeall)
display.setStatusBar(display.HiddenStatusBar)
– Main function - MUST return a display.newGroup()
function new()
local localGroup = display.newGroup()
local buildingLeft1 = display.newImage(“buildingLeft.png”)
buildingLeft1.x = 11
buildingLeft1.y = 480
local buildingLeft2 = display.newImage(“buildingLeft.png”)
buildingLeft2.x = 11
buildingLeft2.y = 0
local buildingRight1 = display.newImage(“buildingRight.png”)
buildingRight1.x = 309
buildingRight1.y = 480
local buildingRight2 = display.newImage(“buildingRight.png”)
buildingRight2.x = 309
buildingRight2.y = 0
local backButton = display.newImage(“backbutton.png”)
local function goToMainMenu( event )
if event.phase == “ended” then
director:changeScene(“MainMenu”, “fade”)
end
end
backButton:addEventListener(“touch”,goToMainMenu)
backButton.x = 160
backButton.y = 420
localGroup:insert(backButton)
localGroup:insert(buildingLeft1)
localGroup:insert(buildingLeft2)
localGroup:insert(buildingRight1)
localGroup:insert(buildingRight2)
local tPrevious = system.getTimer()
local speed = 1.2
local bgSpeed = .1
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time
local yOffset = ( 0.2 * tDelta )
buildingLeft1.y = buildingLeft1.y + yOffset*speed
buildingRight1.y = buildingRight1.y + yOffset*speed
buildingLeft2.y = buildingLeft2.y + yOffset*speed
buildingRight2.y = buildingRight2.y + yOffset*speed
if buildingLeft1.y > 720 then
buildingLeft1:translate( 0 , -480*2 )
end
if buildingRight1.y > 720 then
buildingRight1:translate( 0 , -480*2 )
end
if buildingLeft2.y > 720 then
buildingLeft2:translate( 0 , -480*2 )
end
if buildingRight2.y > 720 then
buildingRight2:translate( 0 , -480*2 )
end
end
Runtime:addEventListener(“enterFrame”, move)
– MUST return a display.newGroup()
return localGroup
end
[/code] [import]uid: 9968 topic_id: 3272 reply_id: 303272[/import]
