cocoscreator开发对战类游戏,两个手机发射炮弹使用同样的角度,力度,重力加速度,炮弹轨迹有时不相同,自己实现了fixedupdate还是不行。
主要代码如下:
fixedUpdate: function (dt) {
console.log(“fixedUpdate—” + dt);
this._speedY += this.gravity * dt;
this.node.x += this._speedX * dt;
this.node.y += this._speedY * dt;
},
update: function (dt) {
if(!this._isLaunch){
return;
}
this._num_dt += dt;
var k = Math.floor(this._num_dt / (1.0 / 50.0));
if (k >= 1)
{ // 保证炮弹总是有50帧/秒的速率
for (var i = 0; i < k; i++)
{
this.fixedUpdate(1.0 / 50.0);
}
this._num_dt = this._num_dt - k * (1.0 / 50.0);
}
},