문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top