Hi,
I create an object using a module then I move it using enterFrame event. I then have a touch event set-up in a seperate module, and when object touched this stops all movement to object. If i use print to check if enterFrame is working properly, I find that its working fine.
I think this maybe a Corona SDK limitation, due to this: http://docs.coronalabs.com/guide/physics/limitations/index.html
********Is there a way to code this?
-
I want to spawn object using separate module
-
I want to have object move to the right, and continue moving after being touched.
-
I want to be able to set up touch event in seperate module
– LEVEL SCENE
function scene1:create(event)
local floatingGround = display.newRect( centerX, 200, display.contentWidth, 20 )
physics.addBody( floatingGround, “static”, {friction = 1})
M.moduleIcon = spawnEnem.spawn({
image = “icon.png”,
objTable = M.lilEnemTable,
hasBody = true,
density = 1,
friction = 1,
bounce = 1,
bodyType = “dynamic”,
})
end
function scene1:show(event)
if event.phase == “did” then
function gameLoop(event)
M.moveEnem ({
obj = M.moduleIcon,
})
end
M.moduleIcon.touch = M.touchLilEnem
M.moduleIcon:addEventListener( “touch”, M.moduleIcon )
Runtime:addEventListener( “enterFrame”, gameLoop )
end
end
– SPAWNENEM aka the OBJECT
local M = {}
M.spawn = function(parameter)
local object = display.newImage( parameter.image , 200, 200 )
object.table = parameter.objTable
object.index = #object.table + 1
object.myName = object.index
object.table[object.index] = object
local hasBody = parameter.hasBody
if hasBody then
object.density = parameter.density or 0.1
object.friction = parameter.friction or 1
object.bounce = parameter.bounce or 0.1
object.isSensor = parameter.isSensor or false
object.bodyType = parameter.bodyType or “dynamic”
object.filterTable = parameter.filterTable or nil
physics.addBody(object, object.bodyType, {object.density, object.friction, object.bounce, object.isSensor, filter = object.filterTable})
end
return object
end – End of spawnFunction
return M
–M aka TOUCH and MOVEMENT module
local M = {}
M.spawn = function(parameter)
local object = display.newImage( parameter.image , 200, 200 )
object.table = parameter.objTable
object.index = #object.table + 1
object.myName = object.index
object.table[object.index] = object
local hasBody = parameter.hasBody
if hasBody then
object.density = parameter.density or 0.1
object.friction = parameter.friction or 1
object.bounce = parameter.bounce or 0.1
object.isSensor = parameter.isSensor or false
object.bodyType = parameter.bodyType or “dynamic”
object.filterTable = parameter.filterTable or nil
physics.addBody(object, object.bodyType, {object.density, object.friction, object.bounce, object.isSensor, filter = object.filterTable})
end
return object
end – End of spawnFunction
return M
This mental block has stopped all production on my game that I’ve been working months on, if anyone can let me know if there is a solution to my problem or do I have to reconstruct my whole game…
Thank you,
-Nick