Esempio n. 1
0
 /**
  * Detaches this entity from the scene and disposes its sprite. Unregisters it from the physics
  * simulation and destroys its body.
  */
 public void destroySelf() {
   acquireEngineLock();
   unregister();
   bodySpriteConnector.getShape().dispose();
   physicsWorld.destroyBody(bodySpriteConnector.getBody());
   bodySpriteConnector = null;
   releaseEngineLock();
 }
Esempio n. 2
0
 /** Returns the height of the entity. */
 public float getHeight() {
   return ((Sprite) bodySpriteConnector.getShape()).getHeight();
 }
Esempio n. 3
0
 /** Returns the width of the entity. */
 public float getWidth() {
   return ((Sprite) bodySpriteConnector.getShape()).getWidth();
 }
Esempio n. 4
0
 /** Returns y-coordinate of center of entity in scene coordinates. */
 public float getCenterY() {
   return bodySpriteConnector.getShape().getSceneCenterCoordinates()[Sprite.VERTEX_INDEX_Y];
 }
Esempio n. 5
0
 /** Attaches this entity to the scene and registers it to the physics simulation. */
 public void registerSelf() {
   engine.getScene().attachChild(bodySpriteConnector.getShape());
   engine.getScene().registerUpdateHandler(this);
   physicsWorld.registerPhysicsConnector(bodySpriteConnector);
 }
Esempio n. 6
0
 private void unregister() {
   engine.getScene().detachChild(bodySpriteConnector.getShape());
   engine.getScene().unregisterUpdateHandler(this);
   physicsWorld.unregisterPhysicsConnector(bodySpriteConnector);
 }
Esempio n. 7
0
 /** Returns the distance between this entity and the given entity in meters. */
 public float getDistanceMeters(Entity other) {
   Vector2 thisPos = bodySpriteConnector.getBody().getPosition();
   Vector2 otherPos = other.bodySpriteConnector.getBody().getPosition();
   return thisPos.dst(otherPos);
 }
Esempio n. 8
0
 /** Applies the given force at the mass center of the entity. */
 public void applyForce(float forceX, float forceY) {
   Vector2 position = bodySpriteConnector.getBody().getPosition();
   bodySpriteConnector.getBody().applyForce(forceX, forceY, position.x, position.y);
 }
Esempio n. 9
0
 /** Returns the mass of the entity. */
 public float getMass() {
   return bodySpriteConnector.getBody().getMass();
 }
Esempio n. 10
0
 /** Sets the velocity of this entity. */
 public void setLinearVelocity(float speedX, float speedY) {
   bodySpriteConnector.getBody().setLinearVelocity(speedX, speedY);
 }
Esempio n. 11
0
 /**
  * Returns a vector holding the linear velocity of the entity. The vector should be returned to
  * the vector pool by calling Vector2Pool.recycle(v);
  */
 public Vector2 getLinearVelocity() {
   return Vector2Pool.obtain(bodySpriteConnector.getBody().getLinearVelocity());
 }