简体   繁体   English

AndEngine和Box2D碰撞检测

[英]Andengine and box2d collision detection

I'm using AndEngine and Box2d in android application. 我在Android应用程序中使用AndEngine和Box2d。
What to I have to do so that when player and coin collide, the player goes through coin without hitting against it as if it is a wall? 我该怎么做,以便当玩家和硬币碰撞时,玩家穿过硬币而不碰到它就像是一堵墙吗?

public class GameScene extends Scene {
  GameScene() {
    Body playerBody = PhysicsFactory.createBoxBody(world, playerSprite, BodyType.DynamicBody, fixtureDef);
    PhysicsConnector playerConnector = new PhysicsConnector(playerSprite, playerBody, true, false);
    world.registerPhysicsConnector(playerConnector);

    Body coinBody = PhysicsFactory.createBoxBody(world, coinSprite, BodyType.StaticBody, fixtureDef);
    PhysicsConnector coinConnector = new PhysicsConnector(coinSprite, coinBody, true, false);
    world.registerPhysicsConnector(coinConnector);
  }

  private ContactListener createContactListener(){
    //if player and coin collide --> destroy coin
  }
}

Read about sensor fixtures in Box2D. 了解Box2D中的传感器固定装置 You want your coin to be a sensor. 您希望硬币成为传感器。 From the Box2D manual: 从Box2D手册中:

Sometimes game logic needs to know when two fixtures overlap yet there should be no collision response. 有时,游戏逻辑需要知道两个固定装置何时重叠,但不应有碰撞响应。 This is done by using sensors. 这是通过使用传感器完成的。 A sensor is a fixture that detects collision but does not produce a response. 传感器是检测碰撞但不产生响应的固定装置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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