Physics Collisions.... yea, I'm asking a n00B question

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 )

I want to add, that I changed the player to static, and while I'm touch-and-dragging, its yellow, when I stop, it turns grey.

The player has the ability to fire a bullet, and when I added it as a physics body, dynamic it stayed yellow and I got collisions with the player, but not anything else.

I'm at a loss.

Okay this is the "all objects have to be in the same display group" problem.

My player was not in the "backgroundGroup" where all the board elements were placed.

I added my player to the backgroundGroup and now I'm getting collisions, but because the backgroundGroup.x is changing to scroll the background, as soon as I touch the player, it blinks away (I'm assuming it's because player.x is getting set to event.x as part of the drag operation. But the event.x is in screen coordinate space, which I suspect is jumping my player back to the begging of the level.

I tried adding the backgroundGroup.x to my player's .x but it just zoomed off the screen too.

ARGGGHHHHHHHHHH!

views:1712 update:2011/12/1 20:56:45
corona forums © 2003-2011