From d68eaa614fa082e8c8a5b122168957313cc5c3dd Mon Sep 17 00:00:00 2001 From: Michal Stawinski Date: Fri, 7 Jun 2013 12:25:45 +0200 Subject: [PATCH] Add IEntity::get|setRorationOffset This change affects only how Entities are drawn. It does not modify values returned by get|setRotation. This is wanted since some external tools assume that Sprites' textures can be rotated regardless of the whole Sprite's rotation 0. It could be fixed by intoducing custom classes but this solution is much more generic. It also seems quite safe. --- src/org/andengine/entity/Entity.java | 14 +++++++++++++- src/org/andengine/entity/IEntity.java | 3 +++ .../menu/item/decorator/BaseMenuItemDecorator.java | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/org/andengine/entity/Entity.java b/src/org/andengine/entity/Entity.java index dbfc92b69..458ff5acc 100644 --- a/src/org/andengine/entity/Entity.java +++ b/src/org/andengine/entity/Entity.java @@ -86,6 +86,7 @@ public void call(final IEntity pEntity) { protected float mHeight; protected float mRotation = IEntity.ROTATION_DEFAULT; + protected float mRotationOffset = IEntity.ROTATION_OFFSET_DEFAULT; protected float mRotationCenterX = IEntity.ROTATION_CENTER_X_DEFAULT; protected float mRotationCenterY = IEntity.ROTATION_CENTER_Y_DEFAULT; @@ -421,6 +422,16 @@ public void setRotation(final float pRotation) { this.mParentToLocalTransformationDirty = true; } + @Override + public float getRotationOffset() { + return this.mRotationOffset; + } + + @Override + public void setRotationOffset(final float pRotationOffset) { + this.mRotationOffset = pRotationOffset; + } + @Override public float getRotationCenterX() { return this.mRotationCenterX; @@ -1414,6 +1425,7 @@ public void reset() { this.mChildrenVisible = true; this.mChildrenIgnoreUpdate = false; + this.mRotationOffset = IEntity.ROTATION_OFFSET_DEFAULT; this.mRotation = 0; this.mScaleX = 1; this.mScaleY = 1; @@ -1550,7 +1562,7 @@ protected void applyTranslation(final GLState pGLState) { } protected void applyRotation(final GLState pGLState) { - final float rotation = this.mRotation; + final float rotation = this.mRotation + this.mRotationOffset; if (rotation != 0) { final float localRotationCenterX = this.mLocalRotationCenterX; diff --git a/src/org/andengine/entity/IEntity.java b/src/org/andengine/entity/IEntity.java index ab8b2779c..7807f0b44 100644 --- a/src/org/andengine/entity/IEntity.java +++ b/src/org/andengine/entity/IEntity.java @@ -37,6 +37,7 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable, ITou public static final float OFFSET_CENTER_Y_DEFAULT = 0.5f; public static final float ROTATION_DEFAULT = 0; + public static final float ROTATION_OFFSET_DEFAULT = 0; public static final float ROTATION_CENTER_X_DEFAULT = 0.5f; public static final float ROTATION_CENTER_Y_DEFAULT = 0.5f; @@ -115,6 +116,8 @@ public interface IEntity extends IDrawHandler, IUpdateHandler, IDisposable, ITou public boolean isRotated(); public float getRotation(); public void setRotation(final float pRotation); + public float getRotationOffset(); + public void setRotationOffset(final float pRotationOffset); public float getRotationCenterX(); public float getRotationCenterY(); diff --git a/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java b/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java index 55361136d..cf403568e 100644 --- a/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java +++ b/src/org/andengine/entity/scene/menu/item/decorator/BaseMenuItemDecorator.java @@ -259,6 +259,16 @@ public void setRotation(final float pRotation) { this.mMenuItem.setRotation(pRotation); } + @Override + public float getRotationOffset() { + return this.mMenuItem.getRotationOffset(); + } + + @Override + public void setRotationOffset(final float pRotation) { + this.mMenuItem.setRotationOffset(pRotation); + } + @Override public float getRotationCenterX() { return this.mMenuItem.getRotationCenterX();