Jump to content

How to Call a Function with key.isDown?


DallOner
 Share

Recommended Posts

Hello everyone! apologize in advance for my poor English.

 

The thing is I've been working on a mini game of roulette machines, I have divided my game with gameStates(boot, gameStates, load, stand, play, win and lose). so some mechanics is: to start the state of play should create an image preloaded on my state of load, this will be a zodiac sign, then press the space key image should be removed and display a sprite sheet which is appended an animation.

 

Something like this:

var winState = {	create: function(){			//Este estado servira de test para presion/accion de boton...		var sta1 = game.add.image(300, 150, 'geminis');		sta1.scale.setTo(0.2);		game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);		if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)){						rotateAnim();                }	},	rotateAnim: function(sta1){		sta1.destroy();		var sta2 = game.add.image(300, 150, 'signos');		sta2.animations.add('rotate');		sta2.animations.play('rotate', 1, true);	}};

BUT I didn't get the expected result.

 

The only thing I desired result is obtained with the method onInputDown (Mouse):

//In Create: Function();var sta1 = game.add.sprite(170, 360, 'leo');sta1.scale.setTo(0.17);sta1.anchor.set(0.5);sta1.inputEnabled = true;sta1.events.onInputDown.add(this.stopAnim, this);stopAnim: function(sta1){        //game.state.start('stand');        sta1.destroy();                var signos = game.add.sprite(170, 360, 'signos');        signos.scale.setTo(0.17);        signos.anchor.set(0.5);        signos.animations.add('change');        signos.animations.play('change', 5, true);    }

could someone tell me I'm doing wrong or that I needed to get the same result when you press a key. Thanks a lot for answers!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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