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