Jump to content

How to Call a Function with key.isDown?


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...