Jump to content

How to stop the character from running continuously and jumping while it is still in mid-air?


Deino
 Share

Recommended Posts

Hey everyone, I succeeded in adding animations to my character but it keeps running off the platform, I want it not to jump again until it has reached the platform as well.

var game = new Phaser.Game(800,600,Phaser.AUTO,'gameDiv');var mainState = {	preload: function()	{		game.load.spritesheet('dude','assets/dude.png',32,48);		game.load.image('wh','assets/wallHorizontal.png');	},	create: function()	{		game.physics.startSystem(Phaser.Physics.ARCADE);		game.stage.backgroundColor = '#71c5cf';		this.dude = game.add.sprite(400,330,'dude');		this.wh = game.add.sprite(380,380,'wh');		game.physics.arcade.enable(this.wh);		this.wh.body.immovable = true;		game.physics.arcade.enable(this.dude);		this.dude.body.gravity.y = 1000;		var spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);		spaceKey.onDown.add(this.jump,this);		var lcur = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);		lcur.onDown.add(this.lmove,this);		var rcur = game.input.keyboard.addKey(Phaser.Keyboard.RIGHT);        rcur.onDown.add(this.rmove,this);        game.physics.arcade.enable(this.dude);        this.dude.animations.add('left', [0, 1, 2, 3], 10, true);        this.dude.animations.add('turn', [4], 20, true);        this.dude.animations.add('right', [5, 6, 7, 8], 10, true);	},	update: function()	{     game.physics.arcade.collide(this.dude,this.wh,null,null,this);     if(this.dude.inWorld == false)     {     	game.state.start('main');     }     	},	jump: function()	{		this.dude.body.velocity.y = -300;	},	lmove: function()	{		this.dude.body.velocity.x = -300;		this.dude.animations.play('left');	},	rmove: function()	{		this.dude.body.velocity.x = 300;		this.dude.animations.play('right');	}};game.state.add('main',mainState);game.state.start('main');
Link to comment
Share on other sites

If you want the player animation to be still just use the frame property.

 

Like:

this.dude.frame = 40;

Put that somewhere in your update after an if else condition you like.

 

Like valueerror said. You can check the onFloor() state, and set the sprite frame to whatever you want.

Link to comment
Share on other sites

Thanks, valueerror and hollowdoor, can you provide links for any such tutorial that covers everything? I have seen flappybird and platformer. I understand most of the code in phaser-examples but not all of it. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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