- public class CCRoundBy extends CCIntervalAction {
- boolean turn;// Forward or Reverse round
- float startAngle;// default
- float radius;// Round circle radius
- CGPoint center;// Round circle center point
-
- public boolean isTurn() {
- return turn;
- }
-
- public void setTurn(boolean turn) {
- this.turn = turn;
- }
-
- public float getStartAngle() {
- return startAngle;
- }
-
- public void setStartAngle(float startAngle) {
- this.startAngle = startAngle;
- }
-
- public float getRadius() {
- return radius;
- }
-
- public void setRadius(float radius) {
- this.radius = radius;
- }
-
- public CGPoint getCenter() {
- return center;
- }
-
- public void setCenter(CGPoint center) {
- this.center = center;
- }
-
- /** creates the action */
- public static CCRoundBy action(float duration,boolean a,CGPoint point, float r) {
- return new CCRoundBy(duration, a, point, r);
- }
-
- /** initializes the action */
- protected CCRoundBy(float duration,boolean a,CGPoint point, float r) {
- super(duration);
- turn = a;
- radius = r;
- center = point;
- }
-
- @Override
- public void start(CCNode aTarget) {
- super.start(aTarget);
-
- startAngle = aTarget.getRotation();
- if (turn) {
- ((CCNode)aTarget).setPosition(CGPoint.ccpAdd(center, CGPoint.ccp(-radius, 0)));
- }
- else {
- ((CCNode)aTarget).setPosition(CGPoint.ccpAdd(center, CGPoint.ccp(radius, 0)));
- }
- }
-
- @Override
- public void update(float t) {
- // XXX: shall I add % 360
- float rotate = (startAngle + 360.0f * t );
- if (turn) {
- rotate *= -1;
- }
- target.setRotation(rotate);
- float fradian = (float) (rotate * Math.PI / 180.0f);
- CGPoint pos = CGPoint.ccp(center.x + radius * MathUtils.sin(fradian),
- center.y + radius * MathUtils.cos(fradian));
- target.setPosition(pos);
- }
- @Override
- public CCIntervalAction reverse() {
- boolean result = !turn;
- return action(duration, result, center, radius);
- }
- }
posted @
2013-04-28 16:47
天边的星星
阅读(
1544)
评论()
编辑
收藏
举报