Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

onInputDown shenanigans


programmerJohn
 Share

Recommended Posts

<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

 Share

  • Recently Browsing   0 members

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