Mattward

Neither Gravity or Collision works (Arcade)

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!

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
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 :(

Share this post


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.