请问我在用3.1版本移植2.4版本2D游戏时,按照步骤首先创建一个重复跳动的小球。代码如下:
全局变量:
private accLeft:boolean = false;
private accRight:boolean = false;
private xSpeed:number = 0;
private hVer3: Vec3 = new Vec3(0,-120,0);
runJumpAction():Tween {
let jumpUp = tween().by(this.jumpDuration,{position: new Vec3(0,this.jumpHeight,0)},{easing: 'sineOut'});
let jumpDown = tween().by(this.jumpDuration,{position: new Vec3(0,-this.jumpHeight,0)},{easing: 'sineIn'});
let targetTween = tween().sequence(jumpUp,jumpDown);
return tween().repeatForever(targetTween);
}
随后按照逻辑在update生命周期内代码如下:
update (deltaTime: number) {
if (this.accLeft) {
this.xSpeed -= this.accel * deltaTime;
}else if (this.accRight) {
this.xSpeed += this.accel * deltaTime
}
if (Math.abs(this.xSpeed) > this.maxMoveSpeed) {
this.xSpeed = this.maxMoveSpeed * this.xSpeed / Math.abs(this.xSpeed)
}
this.hVer3.x += this.xSpeed*deltaTime;
// this.node.position = this.hVer3;
this.node.setPosition(this.hVer3);
// this._targetTw.set({position:this.hVer3});
// console.log(this._targetTw)
}
现在的问题是逻辑内的hVer3的x值是变动了,但是小球依然不动。请教如何解决,谢谢!