gpt4 book ai didi

javascript - 如何平滑cocos2d-JS轮子的旋转

转载 作者:行者123 更新时间:2023-11-28 05:54:21 25 4
gpt4 key购买 nike

我想做一个像这样旋转的轮子,但是旋转的时候不顺畅。我怎样才能让它顺利运行? 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);

最佳答案

我总是创建一个扩展 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.
}
})

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

关于javascript - 如何平滑cocos2d-JS轮子的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37824622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com