0
votes

I am creating my first game in Andengine (GLES 2) and using Box2D for physics.

The collision detection works but doesn't seem to take into account the alpha values on the png files (I think this is what is happening) as the collision happens way before the two sprites actually touch. I don't need the collision to be pixel perfect just reasonably accurate.

This is how I set up the collision detection:

    final CharacterSprite characterSprite = new CharacterSprite(CAMERA_WIDTH/2, CAMERA_HEIGHT/2, this.mCharacterTextureRegion, this.getVertexBufferObjectManager()); 

    mPhysicsWorld = new FixedStepPhysicsWorld(60, new Vector2(0, 0), false); 
    scene.registerUpdateHandler(mPhysicsWorld);

    playerBody = PhysicsFactory.createBoxBody(mPhysicsWorld, characterSprite, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(0, 0, 0));
    playerBody.setUserData("player");

    characterSprite.setBody(playerBody);

    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(characterSprite, playerBody, true, true));

    mPhysicsWorld.setContactListener(createContactListener());

    attachSprites(scene);

Thank you

1
Unfortunately, you may need to cut your sprites to make more accurate boxes. I haven't messed much with AndEngine, but if they detect collisions with included alpha values there isn't much you can do. Is your background transparent? - zgc7009
The function "createBoxBody" should be a clue that the body you are creating is a rectangular shape and has nothing to do with pixels or png files at all. Try rendering the 'debug draw' display so you can see exactly what the physics engine is doing. - iforce2d

1 Answers

1
votes

Well then use shape other than a box (circle might be a good choice) or use a custom sized box that doesn't go all the way around your sprite. If you want even more precision go with polygon or even multiple polygons.