programmerJohn Posted April 30, 2018 Share Posted April 30, 2018 <html> <head> <script src="phaser.js"></script> </head> <body> <h1>Card Game</h1> <script> var config = { type: Phaser.AUTO, width: 1200, height: 1000, scene: { preload: preload, create: create, update: update } }; game = new Phaser.Game(config); var counter = 0; function preload () { this.load.image('background', 'assets/background.jpg'); this.load.image('wolf', 'assets/wolf.png') } function create () { this.add.image(600, 500, 'background'); creature = this.add.group(); creature.inputEnableChildren = true; wolf = creature.create(600, 500, 'wolf'); wolf.onInputDown.add(listener, this); } function listener(sprite){ console.log('click'); } function update () { } </script> </body> </html> The code above is supposed to log "click" on the console whenever the wolf image is clicked but instead I get an error Quote Uncaught TypeError: Cannot read property 'add' of undefined after multiple hours of trying to fix it, I conceded and came to ask for help. Many thanks in advanced. Link to comment Share on other sites More sharing options...
samme Posted April 30, 2018 Share Posted April 30, 2018 wolf.(undefined).add(listener, this); Link to comment Share on other sites More sharing options...
samme Posted April 30, 2018 Share Posted April 30, 2018 Are you using Phaser 2 or 3? Link to comment Share on other sites More sharing options...
programmerJohn Posted April 30, 2018 Author Share Posted April 30, 2018 I'm using Phaser 3. I had used Phaser 2 a while ago and I was relatively proficient and assumed not much changed in phaser 3 other than some quality of life features. It appears I'm wrong though. I might revert back to phaser 2 Link to comment Share on other sites More sharing options...
snowbillr Posted May 1, 2018 Share Posted May 1, 2018 Phaser 3 has a different API than Phaser 2 did for interacting with game objects. Take a look at the example here: https://labs.phaser.io/view.html?src=src\input\game object\on down event.js Link to comment Share on other sites More sharing options...
Recommended Posts