[lua]local physics = require (“physics”)
physics.start()
local w = display.contentWidth
local h = display.contentHeight
local cx = display.contentCenterX
local cy = display.contentCenterY
elements = display.newGroup ()
elements.anchorChildren = true
elements.anchorX = 0
elements.anchorY = 1
elements.x = 0
elements.y = 0
gameStarted = false
local floor = display.newRect( 0, 0, 320, 80 )
floor.x = cx
floor.y = cy
physics.addBody( floor, “static”, { bounce=0} )
local player = display.newRect( 80, 80, 20, 20 )
player:setFillColor( 0, 0, 1 )
physics.addBody( player, “dynamic”, { density=3.0, friction=10.5, bounce=0 } )
function onCollision ( event )
if ( event.phase == “began” ) then
print (“1”)
end
end
function speedUp (event)
if event.phase == “began” then
if gameStarted == false then
addRedTimer = timer.performWithDelay ( 1800, addRed, -1)
moveRedTimer = timer.performWithDelay ( 20, moveRed, -1)
gameStarted = true
end
end
end
function moveRed ()
for a = elements.numChildren, 1, -1 do
if ( elements[a].x > -100 ) then
elements[a].x = elements[a].x - 7
else
elements:remove (elements[a])
elements[a] = nil
end
end
end
function addRed ()
Red = display.newRect( 90, 80, 20, 20 )
Red.x = 320
Red.y = 180
Red:setFillColor( 1, 0, 0 )
physics.addBody( Red, “static”, { density=3.0, friction=0.5, bounce=0 } )
elements:insert (Red)
end
function PlayerJump ( event )
if event.phase == “began” then
player:applyForce ( 0, -251, player.x, player.y )
end
end
Runtime:addEventListener (“touch”, PlayerJump)
Runtime:addEventListener (“touch”, speedUp)
player:addEventListener (“collision”, onCollision)
[/lua]
So my problem is about my player’s collisions
As you see, Player is dynamic. The Red and The Floor are static
What I wrote is when collision on player, It print (“1”)
However, it print (“1”) when player hit floor and red
What i want is to print (“1”) when player hit the red, and not print anything when player hit the floor
Thanks alot