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

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...
 Share

  • Recently Browsing   0 members

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