Hey all, I wanted to see if anyone can confirm that Runtime events do not work when the object is inside an external module? I have the below player.lua:
[lua]local E = {}
local function createPlayer()
player = display.newRect( 50,50, 100, 100 )
physics.addBody(eagle, { density = 1.0, friction = 0.3, bounce = 0 })
player .isFixedRotation = true
return player
end
E.createPlayer = createPlayer
return E[/lua]
And I have the scene1.lua:
[lua]local storyboard = require “storyboard”
local physics = require “physics”
physics.start()
local player = require (“player”)
local scene = storyboard.newScene()
– forward declarations
local object2, player
local function onSceneTouch( self, event )
if event.phase == “began” then
storyboard.gotoScene( “scene2”, “fade”, 400 )
return true
end
end
– enterFrame event listener function
local function onUpdate( event )
if event.phase == (“began”) then
player:applyLinearImpulse(0, -5, player.x, player.y)
print(“player.x =”…player.x)
elseif ( event.phase == ‘canceled’ or event.phase == ‘ended’ ) then
end
return nil
end
function scene:createScene( event )
local group = self.view
local player
player = hero.createPlayer()
group:insert(player) – will be destroyed when scene changes
object2 = display.newRect( 50,50, 100, 100 )
physics.addBody(object2, { density = 1.0, friction = 0.3, bounce = 0 })
ground = display.newRect(0,300, 500, 32)
physics.addBody(ground, “static”,{ density = 1.0, friction = 0.3, bounce = 0 })
group:insert( object2 )
group:insert( ground )
object2.touch = onSceneTouch
object2:addEventListener(“touch”, object2)
end
scene:addEventListener( “createScene”, scene )
function scene:willEnterScene( event )
– object1.isVisible = false
object2.isVisible = false
end
scene:addEventListener( “willEnterScene”, scene )
function scene:enterScene( event )
– object1.isVisible = true
object2.isVisible = true
Runtime:addEventListener( “touch”, onUpdate )
end
scene:addEventListener( “enterScene”, scene )
function scene:exitScene( event )
– object1.isVisible = true
object2.isVisible = true
Runtime:removeEventListener( “touch”, onUpdate )
end
scene:addEventListener( “exitScene”, scene )
function scene:didExitScene( event )
print( “This scene has fully transitioned out and is no longer the active scene.” )
end
scene:addEventListener( “didExitScene”, scene )
return scene[/lua]
In this format, the Runtime listener will not act on the player object created in the player.lua module. I can initiate the player function outside of the createScene option but obviously that creates other problems. Does anyone know of any other way around this? [import]uid: 135394 topic_id: 30468 reply_id: 330468[/import]