* 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
tableBounds.height = height;\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
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.rotation != 0 || actor.scaleX != 1 || actor.scaleY != 1)\r
- throw new GdxRuntimeException("Only unrotated and unscaled actors may use this method.");\r
- localCoords.x += actor.x;\r
- localCoords.y += actor.y;\r
- actor = actor.parent;\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 (rotation != 0 || scaleX != 1 || scaleY != 1)\r
- throw new GdxRuntimeException("Only unrotated and unscaled actors may use this method.");\r
- localCoords.x += x;\r
- localCoords.y += y;\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
final float scaleY = this.scaleY;\r
final float childX = x;\r
final float childY = y;\r
-\r
if (rotation == 0) {\r
if (scaleX == 1 && scaleY == 1) {\r
parentCoords.x -= childX;\r
} else {\r
final float originX = this.originX;\r
final float originY = this.originY;\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
+ 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 = this.originX;\r
final float originY = this.originY;\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 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