Hello everybody - here a special problem:
Two rectangle bodies overlay each other (static) - a third rectangle (dynamic) is placed in the middle of the overlay. Now I get two collision detections - but I just want to get it from the top static rectangle. How can I manage it? Here my script:
local physics = require “physics”
physics.start()
–physics.setDrawMode( “hybrid” )
physics.setGravity( 0, 10 )
local myRectangle1 = display.newRect(150, 150, 250, 250)
myRectangle1.strokeWidth = 3
myRectangle1:setFillColor(140, 140, 140)
myRectangle1:setStrokeColor(255, 0, 0)
physics.addBody( myRectangle1, “static”)
myRectangle1.name=“red”
local myRectangle2 = display.newRect(250, 250, 250, 250)
myRectangle2.strokeWidth = 3
myRectangle2:setFillColor(140, 140, 140)
myRectangle2:setStrokeColor(0, 255, 0)
physics.addBody( myRectangle2, “static”)
myRectangle2.name=“green”
local player = display.newRect(300, 300, 50, 50)
player.strokeWidth = 3
player:setFillColor(140, 140, 140)
player:setStrokeColor(0, 0, 255)
physics.addBody( player, “dynamic”)
player.name=“player”
local function onLocalCollision( self, event )
if ( event.phase == “began”) then
print( self.name … ": collision began with " … event.other.name )
elseif ( event.phase == “ended” ) then
print( self.name … ": collision ended with " … event.other.name )
end
end
player.collision = onLocalCollision
player:addEventListener( “collision”, player )
Output:
player: collision began with green
player: collision began with red
But I just want to get the highest position - the green one - red should be ignored!
Any ideas?
Thank you
Anthony [import]uid: 125918 topic_id: 31074 reply_id: 331074[/import]
