Hi Nice to find this community,
- Question #1
can i know if character landed on ground?
I found this example already
How to catch when player hit the ground after jump
but its always returning false for some reason,
the specific code:
class SceneMain extends Phaser.Scene {
// other methods
update() {
// code...
// console.log( this.catCharacter.body.onFloor() ) - always returning false
if( this.catCharacter.body.onFloor() ) {
console.log('cat on ground');
}
}
endJump() {
console.log('endjump');
this.timer.remove();
this.catCharacter.setVelocityY(-350);
this.power=0;
}
startJump() {
console.log('startjump');
this.timer=this.time.addEvent({ delay: 100, callback: this.tick, callbackScope: this, loop: true });
// this.catCharacter.setVelocityY(-100);
}
}
and uploaded whole code to github also
sceneMain.js - with jumping issue.
- Question #2
I want change character when not moving:
this how i tried to do it.
class SceneMain extends Phaser.Scene {
// other methods here...
update() {
var key_right=this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
var key_left=this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);
var key_up=this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W);
if ( key_left.isDown ) {
if( this.catCharacter.flipX == false ) {
this.catCharacter.flipX=true;
}
this.catCharacter.x-=2;
}
else if ( key_right.isDown ) {
if( this.catCharacter.flipX == true ) {
this.catCharacter.flipX=false;
}
this.catCharacter.x+=2;
}
else {
// relevant code for cat idle animation
console.log('cat idle');
this.catCharacter.setTexture('cat_idle_1');
}
}
}
again the same full scene is here:
Thanks a lot guys!!!