I’m building a basic side scroller and I was NOT planning on using physics.
I have a Runtime “enterFrame” listener that moves a big group that has my background and all of the things I can collide with in a right to left manner. My player avatar is currently a touch and drag to move up, down, left and right avoiding the things that need avoided, running into the things that need run into. Due to the nature of the game I really can’t just test for collisions using the image rectangles as I want the target of the collisions to be a bit smaller.
So I’m implementing physics.
Here’s my relevant code:
local physics = require("physics")
...
physics.start()
physics.setDrawMode( "hybrid" )
physics.setGravity( 0, 0 )
local staticCollisionFilter = { categoryBits = 1, maskBits = 2 }
local playerCollisionFilter = { categoryBits = 2, maskBits = 1 }
...
local blockerBaseShape = { -25,40, 25,40, 25,0, -25,0 }
local blockerPhysics = { density = 10.0, friction = 1.0, bounce = 0.2, shape=blockerBaseShape }
-- blockers are objects that stop your progression.
...
-- this is the level boss in slot 0. All of the object setup stuff is omitted -- and working...
physics.addBody( objects[1], "kinematic", { density=1.5, friction=0.5, bounce=0.8 } )
...
for i=1,numBlockers do
... -- create the objects
physics.addBody( objects[i], "static", blockerPhysics )
end
for i=numBlockers+1, numPickups + numBlockers + 1 do -- add the pick up items after the blockers
... -- create the objects
physics.addBody( objects[i], "kinematic", { density=1.0, friction=0.5, bounce=0.3})
objects[i].isSensor = true
end
...
-- code to create the player
...
physics.addBody(player, "kinematic", { density=1.0, friction=0.5, bounce=0.3})
local function onCollision(event)
print(event.phase .. " " .. event.object1.name .. " is colliding with " .. event.object2.name)
end
Runtime:addEventListener( "collision", onCollision )
So all my objects create properly. I see the debug boxes. The things that are kinematic are purple, the static green. The boxes are where I expect them. But when I run into things, nothing happens. Of course I’ve not programmed any behavior for the collisions yet, but I would expect my print statement to print.
I was using collision Filters, which I will need to implement because it is possible for pickup’s to collide with other blocker and pickup items, and I don’t want those to trigger.
I had also tried making the collision detection only on the player object and that didn’t work either.
What am I missing???
I should add, this is a Storyboard based application, and there is a physics.stop() call in the exitScene event handler.
Help!!!
Thanks
Rob [import]uid: 19626 topic_id: 18387 reply_id: 318387[/import]