Hi,
I have come across something interesting, it may be a bug or I might have missed something…
I have a ball that moves to the right when you touch the screen. There is a big square in its way. There is a little square at the top of the screen which moves the big square up (and out of the way of the ball)
If I put all the code in the one lua file everything works, if the big square is moved up, then the ball goes underneath it no problems, no collision at all.
But as soon as I move it into two files, the square creation into another lua file, for some reason even when the big square is out of the way, the ball seems to hit an invisible object.
My code is below…
thanks
main.lua
local square = require "square"
local physics = require "physics"
physics.start( true )
physics.setDrawMode("normal") -- set to "debug" or "hybrid" to see collision boundaries
--physics.setDrawMode("hybrid")
physics.setGravity( 0, 9.8 ) --\> 0, 9.8 = Earth-like gravity
local cel = display.newRect(0, 0, display.contentWidth, 10)
cel.y = 900
physics.addBody(cel, "static" )
local ball = display.newCircle( 100, 100, 30 )
ball.y = 900
physics.addBody(ball, "dynamic" )
local squareInstance = square.CreateSquare()
local square1 = display.newRect(100 , 100 , 50, 50)
function movement(event)
ball:applyLinearImpulse( 0.1, 0, ball.x, ball.y )
end
function test(event)
squareInstance.y = squareInstance.y - 10
return true
end
square1:addEventListener( "touch", test )
Runtime:addEventListener( "touch", movement )
square.lua
[code]
module(…, package.seeall)
function CreateSquare()
– create group to return
local localGroup = display.newGroup ()
local square = display.newRect(500 , 800 , 100, 100)
physics.addBody(square, “static” )
localGroup:insert(square)
function SquareCollision()
print(“ouch”)
end
square:addEventListener( “collision”, SquareCollision )
return localGroup
end
[/code] [import]uid: 67619 topic_id: 20184 reply_id: 320184[/import]
[import]uid: 12482 topic_id: 20184 reply_id: 78848[/import]