简体   繁体   English

AndEngine Box2D中的Alpha碰撞检测

[英]Collision Detection with Alpha in Box2D for AndEngine

I am creating my first game in Andengine (GLES 2) and using Box2D for physics. 我正在用Andengine(GLES 2)创建我的第一个游戏,并将Box2D用于物理。

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. 碰撞检测有效,但似乎没有考虑png文件上的alpha值(我认为这是发生了什么),因为碰撞发生在两个精灵实际接触之前。 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM