Jump to content

Problems with sprite.events


epicTCK
 Share

Recommended Posts

I have the following code:

var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
function preload(){
	game.load.image('avocad', 'assets/avocad.png');
	game.load.audio('drink','assets/drink.mp3');
}
var drinkSound, avocad;
function create(){
	drinkSound = game.add.audio('drink');
	
	game.stage.backgroundColor = "#FEFACB";
	
	avocad = game.add.sprite(game.world.centerX, game.world.centerY, 'avocad').anchor.set(0.5);
	avocad.inputEnabled  = true;
	avocad.events.onInputDown.add(pour, this);
}

function pour(){
	drinkSound.play();
}

Which doesn't work. It all checks out, but it it throws the following error:

TypeError: avocad.events is undefined
Stack trace:
[email protected]://localhost:8000/avocadGame/game.js:14:2
[email protected]://localhost:8000/avocadGame/phaser.js:29240:13
[email protected]://localhost:8000/avocadGame/phaser.js:71446:9
[email protected]://localhost:8000/avocadGame/phaser.js:71403:13
[email protected]://localhost:8000/avocadGame/phaser.js:71476:9
[email protected]://localhost:8000/avocadGame/phaser.js:72323:13
Phaser.Loader.prototype.xhrLoad/[email protected]://localhost:8000/avocadGame/phaser.js:71875:28

I've followed this example loosely. Could I get some help?

Link to comment
Share on other sites

Dam beat me to it :L

To elaborate. You may be thinking that a sprite object is being returned from the first function game.add.sprite(...) just fine, then you are just doing .anchor.set(...) on that object, but this is not the case.

Do console.log(avocad); just after the avocad = game.add.sprite... line to see what I mean.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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