I have two items on screen that I move around using gtween. I move the physics bodies around with the sprites. No issue there. Everything works fine. I use physics as it seemed to be the easiest way to detect collisions (Couldn't find a way to detect collisions between images that ignored transparent areas.)
However when I try and detect a collision between them nothing triggers.
This is some of the code I am using. Some taken from forum posts and adjusted for my uses. Basically trying to learn to code purely in the Gideros way.
Any ideas where I am failing.
Mike
world:addEventListener(Event.BEGIN_CONTACT, onBeginContact)
local function onBeginContact(event)
-- you can get the fixtures and bodies in this contact like:
local fixtureA = event.fixtureA
local fixtureB = event.fixtureB
local bodyA = fixtureA:getBody()
local bodyB = fixtureB:getBody()
print("begin contact: "..bodyA.name.." "..bodyB.name)
end
the following is how I create the main player object that I can move around the screen.
function createPlayer()
local frame1 = Bitmap.new(Texture.new("Red3.png"))
frame1:setAnchorPoint(0.5,0.5)
local frame2 = Bitmap.new(Texture.new("Red2.png"))
frame2:setAnchorPoint(0.5,0.5)
local frame3 = Bitmap.new(Texture.new("Red1.png"))
frame3:setAnchorPoint(0.5,0.5)
player1 = MovieClip.new{
{1, 10, frame1},
{11, 20, frame2},
{21, 30, frame3}
}
player1:setPosition(160,64)
local playerBody = world:createBody{b2.DYNAMIC_BODY, position = {x = player1:getX(),y = player1:getY()}}
local playerShape = b2.CircleShape.new(0,8,20)
playerBody:createFixture{shape = playerShape, density = 0,restitution = 0.0, friction = 0.0, isSensor = true}
player1.body = playerBody
playerBody.name = "Player"
playerBody.MovieClip = player1
actors[#actors + 1] = player1
end
function createObject()
item1 = Bitmap.new(Texture.new("Ring.png"))
item1:setAnchorPoint(0.5,0.5)
item1:setPosition(160,320)
local itemBody = world:createBody{b2.DYNAMIC_BODY, position = {x = item1:getX(),y = item1:getY()}}
local itemShape = b2.CircleShape.new(0,4,12)
itemBody:createFixture{shape = itemShape, density = 0,restitution = 0.0, friction = 0.0, isActive = true}
item1.body = itemBody
itemBody.name = "item"
itemBody.MovieClip = item1
actors[#actors + 1] = item1
end
Comments
Mike
http://www.sharksoupstudios.com
and see what happens with the physical models?
it helped me a lot!
www.tntengine.com
Cheers
Mike
http://www.sharksoupstudios.com
Or do this:
Likes: Yan
I am beginning to think that it is impossible. It seems that unless you are letting the physics world do the moving the physics objects cannot be used for detecting collisions.
Let me try and clarify a bit more.
I click somewhere on screen and the sprite moves to that position. The body moves with the sprite by having the line "body:setPosition(sprite:getPosition())" within the enterFrame function.
I get no errors just no trigger.
Mike
http://www.sharksoupstudios.com
but collision works fine...
www.tntengine.com
I am close to forgetting it. Have little enough time at the moment without being defeated by what should be so simple.
Mike
http://www.sharksoupstudios.com
...for moving i'm using the function on the above post. (no gtween)
if you want you can send me the source and i can try to help you..!
Likes: chipster123
www.tntengine.com
Thank you.
Mike
http://www.sharksoupstudios.com
a little error in body definition:
you forgot to type "type=" in the definition of DYNAMIC BODY... ... it happens ..
change the line in function "setupCharacters"
with:
in function createColliders()
hope it helps.
ciao Gianluca.
Likes: chipster123, atilim
www.tntengine.com
Cheers
Mike
Likes: gorkem
http://www.sharksoupstudios.com
www.tntengine.com