I’m learning with the [purple monster] tutorial for model 2.x
However this tutorial is model 2.x
I modified the code for model 3.x
@ccclass('Participant')
export class Participant extends Element {
@property
jumpHeight: quantity = 0;
@property
jumpDuration: quantity = 0;
@property
maxMoveSpeed: quantity = 0;
@property
accel: quantity = 0;
accLeft :boolean
accRight:boolean;
xSpeed:quantity;
setJumpAction() {
return tween(this.node)
.repeatForever(
tween()
.by(this.jumpDuration, { place: v3(0, this.jumpHeight, 0) }, { easing: 'cubicOut' })
.by(this.jumpDuration, { place: v3(0, -this.jumpHeight, 0) }, { easing: 'cubicIn' })
);
}
setInputControl(){
enter.on(Enter.EventType.KEY_DOWN,occasion=>{
swap(occasion.keyCode) {
case KeyCode.ARROW_LEFT:
this.accLeft = true;
break;
case KeyCode.ARROW_RIGHT:
this.accRight = true;
break;
}
});
enter.on(Enter.EventType.KEY_UP,occasion=>{
swap(occasion.keyCode) {
case KeyCode.ARROW_LEFT:
this.accLeft = false;
break;
case KeyCode.ARROW_RIGHT:
this.accRight = false;
break;
}
});
}
onLoad() {
this.accLeft=false;
this.accRight=false;
this.xSpeed=0;
this.setJumpAction().begin();
this.setInputControl();
}
begin() {
}
replace(deltaTime: quantity) {
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.node.setPosition(this.node.getPosition().add3f(this.xSpeed*deltaTime,0,0));
}
}
The purple monster doesn’t transfer left or proper once I press the keyboard.
I can transfer left and proper by commenting out [this.setJumpAction().start();]
(In fact the purple monster is not going to transfer up and down)
What ought to I repair?