I am having trouble with flicking when I click the mouse. The variable on input.on
is returning undefined when I click the mouse. Here is a code snippet that explains my issue. Phaser is a new concept to me.
w : number;
h : number;
velocity:number;
sprite = null;
totalDelta = null;
constructor() {
super({ key: 'Init' });
}
preload(){
this.w = Number(this.game.config.width);
this.h = Number(this.game.config.height);
this.velocity = Number(this.game.config.physics.arcade.gravity.y);
this.createBG();
}
createBG(){
this.add.image(0,0,'background').setOrigin(0);
}
createSprite(){
var x = this.w * 0.1;
this.sprite = this.physics.add.sprite(x ,this.h/2,'sprite').setOrigin(0);
}
create(){
this.createSprite();
this.input.on("pointerdown",this.flick);
}
flick(){
this.sprite.body.velocity.y = -this.velocity;
}