您的位置:首页 > 移动开发 > Cocos引擎

Android Cocos2d旋转动画 图片围绕一个圆心做圆运动

2013-04-28 16:47 477 查看
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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: