Jump to content

Need help with this issue


pablo_bot
 Share

Recommended Posts

I

I'm new to javascript/typescript and phaser. I have extensive experience with Unity3d/C#.

I've got this code...

class App {

game: Phaser.Game;
text: Phaser.Text;
counter = 0;

constructor() {
    this.createGame(800, 600);
}

preload() {
    this.game.load.image("einstein", "phaser2.png");
}

create() {
    var image = this.game.add.sprite(this.game.world.centerX, this.game.world.centerY, "einstein");
    image.anchor.set(0.5);
    image.inputEnabled = true;
    this.text = this.game.add.text(250, 16, "", { fill: "#ffffff" });
    image.events.onInputDown.add(this.clickHandler, this);
}


private clickHandler() {
    this.counter++;
    this.text.text = "You clicked " + this.counter + " times!";
}

private createGame(width: number, height: number) {
    this.game = new Phaser.Game(width, height, Phaser.AUTO, "test-game", { preload: this.preload, create: this.create });
}
}

It runs, but when I click on the image I get an error saying that listener is a require param of add() and that it should be a Function.

Well as far as I can tell, I very clearly have a defined function there as a parameter, but it doesnt work. What am I doing wrong?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...