Jump to content

Neither Gravity or Collision works (Arcade)


Mattward
 Share

Recommended Posts

Hi,

 

I'm making a game with a friend, we have gotten quite far into the development, except the physics has never worked? We keep adding to the game whilst also trying to fix it..  We've evidently had no luck :(

I think when the gameState is set to "Menu", the gravity seems to work, however not when it's set to "Playing".

 

Here is the code: http://pastebin.com/0LNfEcq4

 

Thanks in advance!

Link to comment
Share on other sites

Also, another problem with my code.. When the gameState is set to "Menu", it has 2 buttons.  These buttons do not work however.  Adding a breakpoint I see it doesn't ever get to line 441.  Is there anything I'm doing wrong?

Link to comment
Share on other sites

your code is a bit too long to be quikly debugged.

 

just a few comments:

- no need of these lines in update function:

game.physics.arcade.enable(player, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform1, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform2, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform3, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform4, Phaser.Physics.ARCADE);  player.enableBody = true;

- for changing the state the correct way is:

game.state.start('state_name');

- the buttons must be like :

playButton = game.add.button(playButtonX, playButtonY, 'playButton', playFunction, this);game.add.button(coinCornerButtonX, coinCornerButtonY, 'CoinCorner', coinFunction, this);

(it's better to make one function for each button, and do not put brackets () in the creation of the button)

 

 

I hope this could help you, but it seems you need to read more examples and the official documentation.

Link to comment
Share on other sites

your code is a bit too long to be quikly debugged.

 

just a few comments:

- no need of these lines in update function:

game.physics.arcade.enable(player, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform1, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform2, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform3, Phaser.Physics.ARCADE);game.physics.arcade.enable(platform4, Phaser.Physics.ARCADE);  player.enableBody = true;

- for changing the state the correct way is:

game.state.start('state_name');

- the buttons must be like :

playButton = game.add.button(playButtonX, playButtonY, 'playButton', playFunction, this);game.add.button(coinCornerButtonX, coinCornerButtonY, 'CoinCorner', coinFunction, this);

(it's better to make one function for each button, and do not put brackets () in the creation of the button)

 

 

I hope this could help you, but it seems you need to read more examples and the official documentation.

I'll read more on it, thanks for the help!

Link to comment
Share on other sites

- the buttons must be like :

playButton = game.add.button(playButtonX, playButtonY, 'playButton', playFunction, this);game.add.button(coinCornerButtonX, coinCornerButtonY, 'CoinCorner', coinFunction, this);

(it's better to make one function for each button, and do not put brackets () in the creation of the button)

 

 

I hope this could help you, but it seems you need to read more examples and the official documentation.

 

I'm afraid this doesn't work.. The buttons are still not clickable :(

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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