简体   繁体   中英

How to smooth cocos2d-JS wheel spinning

I want to make a wheel spinning like this, but it not smooth when rotating. How can I make it run smoothly? 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);

I always create a new class extends Sprite and rewrite draw() or update() to do the job.

Here is the example:

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.
  } 
}) 

In order to calculate the speed, you may save some parameter(like current speed, current acceleration speed) to record the status.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM