如何平滑cocos2d-JS车轮旋转

时间:2016-06-15 01:18:55

标签: javascript cocos2d-js

我想让这样的车轮旋转,但旋转时不顺畅。如何让它顺利运行? Demo

        var audioengine = cc.audioEngine;
        audioengine.playMusic(res.Wheel_mp3, false);

        var spinNumber = Math.floor((Math.random()*360) + 0);
        var angle = spinNumber + 13*360;   
        var action = new cc.RotateBy(18, angle);

        var ease = new cc.EaseSineOut(action);

        this.sprite.runAction(ease);

1 个答案:

答案 0 :(得分:0)

我总是创建一个新的类扩展Sprite并重写draw()或update()来完成这项工作。

以下是示例:

var Wheel = Sprite.extend({
  ctor and other function : ...
  draw : function(){
    this._super();

    var speed = this. calculate Speed();
    var rotation = this.getRotation();
    var neoRotation = (rotation+speed)%360;
    this.setRotation(neoRotation)
  },

  caculateSpeed : function(){
    // some function that calculate the speed to simulate acceleration and deceleration.
    // return 0 means not rotate.
     return speed.
  } 
}) 

为了计算速度,您可以保存一些参数(如当前速度,当前加速度)来记录状态。