private String name;\r
private Touchable touchable = Touchable.enabled;\r
private boolean visible = true;\r
- private float x, y;\r
- private float width, height;\r
- private float originX, originY;\r
- private float scaleX = 1, scaleY = 1;\r
- private float rotation;\r
- private final Color color = new Color(1, 1, 1, 1);\r
+ float x, y;\r
+ float width, height;\r
+ float originX, originY;\r
+ float scaleX = 1, scaleY = 1;\r
+ float rotation;\r
+ final Color color = new Color(1, 1, 1, 1);\r
\r
/** Draws the actor. The SpriteBatch is configured to draw in the parent's coordinate system.\r
* {@link SpriteBatch#draw(com.badlogic.gdx.graphics.g2d.TextureRegion, float, float, float, float, float, float, float, float, float)\r
* The default implementation calls {@link Action#act(float)} on each action and removes actions that are complete.\r
* @param delta Time in seconds since the last frame. */\r
public void act (float delta) {\r
- for (int i = 0, n = actions.size; i < n; i++) {\r
+ for (int i = 0; i < actions.size; i++) {\r
Action action = actions.get(i);\r
- if (action.act(delta)) {\r
+ if (action.act(delta) && i < actions.size) {\r
actions.removeIndex(i);\r
action.setActor(null);\r
i--;\r
- n--;\r
}\r
}\r
}\r
while (true) {\r
if (parent == null) return false;\r
if (parent == actor) return true;\r
- parent = parent.getParent();\r
+ parent = parent.parent;\r
}\r
}\r
\r
while (true) {\r
if (actor == null) return false;\r
if (actor == this) return true;\r
- actor = actor.getParent();\r
+ actor = actor.parent;\r
}\r
}\r
\r
\r
/** Sets the x and y. */\r
public void setPosition (float x, float y) {\r
- setX(x);\r
- setY(y);\r
+ this.x = x;\r
+ this.y = y;\r
}\r
\r
public void translate (float x, float y) {\r
- setX(this.x + x);\r
- setY(this.y + y);\r
+ this.x += x;\r
+ this.y += y;\r
}\r
\r
public float getWidth () {\r
\r
/** Returns y plus height. */\r
public float getTop () {\r
- return getY() + getHeight();\r
+ return y + height;\r
}\r
\r
/** Returns x plus width. */\r
public float getRight () {\r
- return getX() + getWidth();\r
+ return x + width;\r
}\r
\r
/** Sets the width and height. */\r
public void setSize (float width, float height) {\r
- setWidth(width);\r
- setHeight(height);\r
+ this.width = width;\r
+ this.height = height;\r
}\r
\r
/** Adds the specified size to the current size. */\r
public void size (float size) {\r
- setWidth(width + size);\r
- setHeight(height + size);\r
+ width += size;\r
+ height += size;\r
}\r
\r
/** Adds the specified size to the current size. */\r
public void size (float width, float height) {\r
- setWidth(this.width + width);\r
- setHeight(this.height + height);\r
+ this.width += width;\r
+ this.height += height;\r
}\r
\r
/** Set bounds the x, y, width, and height. */\r
public void setBounds (float x, float y, float width, float height) {\r
- setX(x);\r
- setY(y);\r
- setWidth(width);\r
- setHeight(height);\r
+ this.x = x;\r
+ this.y = y;\r
+ this.width = width;\r
+ this.height = height;\r
}\r
\r
public float getOriginX () {\r
\r
/** Sets the originx and originy. */\r
public void setOrigin (float originX, float originY) {\r
- setOriginX(originX);\r
- setOriginY(originY);\r
+ this.originX = originX;\r
+ this.originY = originY;\r
}\r
\r
public float getScaleX () {\r
\r
/** Sets the scalex and scaley. */\r
public void setScale (float scale) {\r
- setScaleX(scale);\r
- setScaleY(scale);\r
+ this.scaleX = scale;\r
+ this.scaleY = scale;\r
}\r
\r
/** Sets the scalex and scaley. */\r
public void setScale (float scaleX, float scaleY) {\r
- setScaleX(scaleX);\r
- setScaleY(scaleY);\r
+ this.scaleX = scaleX;\r
+ this.scaleY = scaleY;\r
}\r
\r
/** Adds the specified scale to the current scale. */\r
public void scale (float scale) {\r
- setScaleX(scaleX + scale);\r
- setScaleY(scaleY + scale);\r
+ scaleX += scale;\r
+ scaleY += scale;\r
}\r
\r
/** Adds the specified scale to the current scale. */\r
public void scale (float scaleX, float scaleY) {\r
- setScaleX(this.scaleX + scaleX);\r
- setScaleY(this.scaleY + scaleY);\r
+ this.scaleX += scaleX;\r
+ this.scaleY += scaleY;\r
}\r
\r
public float getRotation () {\r
\r
/** Adds the specified rotation to the current rotation. */\r
public void rotate (float amountInDegrees) {\r
- setRotation(rotation + amountInDegrees);\r
+ rotation += amountInDegrees;\r
}\r
\r
public void setColor (Color color) {\r
* Setting a z-index less than zero is invalid. */\r
public void setZIndex (int index) {\r
if (index < 0) throw new IllegalArgumentException("ZIndex cannot be < 0.");\r
- Group parent = getParent();\r
+ Group parent = this.parent;\r
if (parent == null) return;\r
Array<Actor> children = parent.getChildren();\r
if (children.size == 1) return;\r
/** Returns the z-index of this actor.\r
* @see #setZIndex(int) */\r
public int getZIndex () {\r
- Group parent = getParent();\r
+ Group parent = this.parent;\r
if (parent == null) return -1;\r
return parent.getChildren().indexOf(this, true);\r
}\r
\r
/** Calls {@link #clipBegin(float, float, float, float)} to clip this actor's bounds. */\r
public boolean clipBegin () {\r
- return clipBegin(getX(), getY(), getWidth(), getHeight());\r
+ return clipBegin(x, y, width, height);\r
}\r
\r
/** Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's SpriteBatch. The\r
tableBounds.y = y;\r
tableBounds.width = width;\r
tableBounds.height = height;\r
- Stage stage = getStage();\r
+ Stage stage = this.stage;\r
Rectangle scissorBounds = Pools.obtain(Rectangle.class);\r
- ScissorStack.calculateScissors(stage.getCamera(), stage.getSpriteBatch().getTransformMatrix(), tableBounds, scissorBounds);\r
+ stage.calculateScissors(tableBounds, scissorBounds);\r
if (ScissorStack.pushScissors(scissorBounds)) return true;\r
Pools.free(scissorBounds);\r
return false;\r
\r
/** Transforms the specified point in screen coordinates to the actor's local coordinate system. */\r
public Vector2 screenToLocalCoordinates (Vector2 screenCoords) {\r
- Stage stage = getStage();\r
+ Stage stage = this.stage;\r
if (stage == null) return screenCoords;\r
return stageToLocalCoordinates(stage.screenToStageCoordinates(screenCoords));\r
}\r
return stageCoords;\r
}\r
\r
- /** Transforms the specified point in the actor's coordinates to be in the stage's coordinates. Note this method will ONLY work\r
- * for screen aligned, unrotated, unscaled actors! */\r
+ /** Transforms the specified point in the actor's coordinates to be in the stage's coordinates.\r
+ * @see Stage#toScreenCoordinates(Vector2, com.badlogic.gdx.math.Matrix4) */\r
public Vector2 localToStageCoordinates (Vector2 localCoords) {\r
- Actor actor = this;\r
- while (actor != null) {\r
- if (actor.getRotation() != 0 || actor.getScaleX() != 1 || actor.getScaleY() != 1)\r
- throw new GdxRuntimeException("Only unrotated and unscaled actors may use this method.");\r
- localCoords.x += actor.getX();\r
- localCoords.y += actor.getY();\r
- actor = actor.getParent();\r
- }\r
- return localCoords;\r
+ return localToAscendantCoordinates(null, localCoords);\r
}\r
\r
- /** Transforms the specified point in the actor's coordinates to be in the parent's coordinates. Note this method will ONLY work\r
- * for screen aligned, unrotated, unscaled actors! */\r
+ /** Transforms the specified point in the actor's coordinates to be in the parent's coordinates. */\r
public Vector2 localToParentCoordinates (Vector2 localCoords) {\r
- if (getRotation() != 0 || getScaleX() != 1 || getScaleY() != 1)\r
- throw new GdxRuntimeException("Only unrotated and unscaled actors may use this method.");\r
- localCoords.x += getX();\r
- localCoords.y += getY();\r
+ final float rotation = -this.rotation;\r
+ final float scaleX = this.scaleX;\r
+ final float scaleY = this.scaleY;\r
+ final float x = this.x;\r
+ final float y = this.y;\r
+ if (rotation == 0) {\r
+ if (scaleX == 1 && scaleY == 1) {\r
+ localCoords.x += x;\r
+ localCoords.y += y;\r
+ } else {\r
+ final float originX = this.originX;\r
+ final float originY = this.originY;\r
+ localCoords.x = (localCoords.x - originX) * scaleX + originX + x;\r
+ localCoords.y = (localCoords.y - originY) * scaleY + originY + y;\r
+ }\r
+ } else {\r
+ final float cos = (float)Math.cos(rotation * MathUtils.degreesToRadians);\r
+ final float sin = (float)Math.sin(rotation * MathUtils.degreesToRadians);\r
+ final float originX = this.originX;\r
+ final float originY = this.originY;\r
+ final float tox = localCoords.x - originX;\r
+ final float toy = localCoords.y - originY;\r
+ localCoords.x = (tox * cos + toy * sin) * scaleX + originX + x;\r
+ localCoords.y = (tox * -sin + toy * cos) * scaleY + originY + y;\r
+ }\r
return localCoords;\r
}\r
\r
/** Converts coordinates for this actor to those of a parent actor. The ascendant does not need to be a direct parent. */\r
public Vector2 localToAscendantCoordinates (Actor ascendant, Vector2 localCoords) {\r
Actor actor = this;\r
- while (actor.getParent() != null) {\r
+ while (actor.parent != null) {\r
actor.localToParentCoordinates(localCoords);\r
- actor = actor.getParent();\r
+ actor = actor.parent;\r
if (actor == ascendant) break;\r
}\r
return localCoords;\r
\r
/** Converts the coordinates given in the parent's coordinate system to this actor's coordinate system. */\r
public Vector2 parentToLocalCoordinates (Vector2 parentCoords) {\r
- final float rotation = getRotation();\r
- final float scaleX = getScaleX();\r
- final float scaleY = getScaleY();\r
- final float childX = getX();\r
- final float childY = getY();\r
-\r
+ final float rotation = this.rotation;\r
+ final float scaleX = this.scaleX;\r
+ final float scaleY = this.scaleY;\r
+ final float childX = x;\r
+ final float childY = y;\r
if (rotation == 0) {\r
if (scaleX == 1 && scaleY == 1) {\r
parentCoords.x -= childX;\r
parentCoords.y -= childY;\r
} else {\r
- final float originX = getOriginX();\r
- final float originY = getOriginY();\r
- if (originX == 0 && originY == 0) {\r
- parentCoords.x = (parentCoords.x - childX) / scaleX;\r
- parentCoords.y = (parentCoords.y - childY) / scaleY;\r
- } else {\r
- parentCoords.x = (parentCoords.x - childX - originX) / scaleX + originX;\r
- parentCoords.y = (parentCoords.y - childY - originY) / scaleY + originY;\r
- }\r
+ final float originX = this.originX;\r
+ final float originY = this.originY;\r
+ parentCoords.x = (parentCoords.x - childX - originX) / scaleX + originX;\r
+ parentCoords.y = (parentCoords.y - childY - originY) / scaleY + originY;\r
}\r
} else {\r
final float cos = (float)Math.cos(rotation * MathUtils.degreesToRadians);\r
final float sin = (float)Math.sin(rotation * MathUtils.degreesToRadians);\r
-\r
- final float originX = getOriginX();\r
- final float originY = getOriginY();\r
-\r
- if (scaleX == 1 && scaleY == 1) {\r
- if (originX == 0 && originY == 0) {\r
- float tox = parentCoords.x - childX;\r
- float toy = parentCoords.y - childY;\r
-\r
- parentCoords.x = tox * cos + toy * sin;\r
- parentCoords.y = tox * -sin + toy * cos;\r
- } else {\r
- final float worldOriginX = childX + originX;\r
- final float worldOriginY = childY + originY;\r
- final float fx = -originX;\r
- final float fy = -originY;\r
-\r
- final float x1 = cos * fx - sin * fy + worldOriginX;\r
- final float y1 = sin * fx + cos * fy + worldOriginY;\r
-\r
- final float tox = parentCoords.x - x1;\r
- final float toy = parentCoords.y - y1;\r
-\r
- parentCoords.x = tox * cos + toy * sin;\r
- parentCoords.y = tox * -sin + toy * cos;\r
- }\r
- } else {\r
- if (originX == 0 && originY == 0) {\r
- final float tox = parentCoords.x - childX;\r
- final float toy = parentCoords.y - childY;\r
-\r
- parentCoords.x = (tox * cos + toy * sin) / scaleX;\r
- parentCoords.y = (tox * -sin + toy * cos) / scaleY;\r
- } else {\r
- final float worldOriginX = childX + originX;\r
- final float worldOriginY = childY + originY;\r
- final float fx = -originX * scaleX;\r
- final float fy = -originY * scaleY;\r
-\r
- final float x1 = cos * fx - sin * fy + worldOriginX;\r
- final float y1 = sin * fx + cos * fy + worldOriginY;\r
-\r
- final float tox = parentCoords.x - x1;\r
- final float toy = parentCoords.y - y1;\r
-\r
- parentCoords.x = (tox * cos + toy * sin) / scaleX;\r
- parentCoords.y = (tox * -sin + toy * cos) / scaleY;\r
- }\r
- }\r
+ final float originX = this.originX;\r
+ final float originY = this.originY;\r
+ final float tox = parentCoords.x - childX - originX;\r
+ final float toy = parentCoords.y - childY - originY;\r
+ parentCoords.x = (tox * cos + toy * sin) / scaleX + originX;\r
+ parentCoords.y = (tox * -sin + toy * cos) / scaleY + originY;\r
}\r
return parentCoords;\r
}\r