Exemple #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();
 }
Exemple #2
0
 /** Returns the height of the entity. */
 public float getHeight() {
   return ((Sprite) bodySpriteConnector.getShape()).getHeight();
 }
Exemple #3
0
 /** Returns the width of the entity. */
 public float getWidth() {
   return ((Sprite) bodySpriteConnector.getShape()).getWidth();
 }
Exemple #4
0
 /** Returns y-coordinate of center of entity in scene coordinates. */
 public float getCenterY() {
   return bodySpriteConnector.getShape().getSceneCenterCoordinates()[Sprite.VERTEX_INDEX_Y];
 }
Exemple #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);
 }
Exemple #6
0
 private void unregister() {
   engine.getScene().detachChild(bodySpriteConnector.getShape());
   engine.getScene().unregisterUpdateHandler(this);
   physicsWorld.unregisterPhysicsConnector(bodySpriteConnector);
 }
Exemple #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);
 }
Exemple #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);
 }
Exemple #9
0
 /** Returns the mass of the entity. */
 public float getMass() {
   return bodySpriteConnector.getBody().getMass();
 }
Exemple #10
0
 /** Sets the velocity of this entity. */
 public void setLinearVelocity(float speedX, float speedY) {
   bodySpriteConnector.getBody().setLinearVelocity(speedX, speedY);
 }
Exemple #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());
 }