javascript - how do you trigger an event on phaser.js by clicking anywhere js -


in phaser.js game, (flappy bird), want bird "flap" every time anywhere clicked. tutorial following shows how initiate when space bar pressed. how can make happen clicking anywhere?

var game = new phaser.game(400, 490, phaser.auto, 'game_div'); var main_state = {     preload: function () {         this.game.stage.backgroundcolor = '#71c5cf';         this.game.load.image('bird', '../img/bird.png');     },     create: function () {         this.game.load.image('bird')     },     update: function () {      } } 

edit: using phonegap, syntax effect answer?

that use phaser js doesnt mean cannot use standard js:

window.addeventlistener("click",function(event){   main_state.flap();   event.stoppropagation();//prevent phaser detection },false);   var main_state = {       game = new phaser.game(400, 490, phaser.auto, 'game_div'),      preload: function () { this.game.stage.backgroundcolor = '#71c5cf'; this.game.load.image('bird', '../img/bird.png'); },      create: function () { this.game.load.image('bird') },       update: function () { },      flap:function(){//your flap code      }      }; 

just add flap function in main_state object. this.game doesnt work. use game instead


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -