Jump to content

onBeginContact not dispatched


Go to solution Solved by MaximeC,

Recommended Posts

Hi,

 

I have refactored my code in order to use states and classes. I now have Boot, Preload, MainMenu and Game classes. The code is cleaner but the callback associated to the onBeginContact is not called anymore. Without classes, it was working as expected.

 

 

In the create of Boot.js, I set the physics engine:

this.game.physics.startSystem(Phaser.Physics.P2JS);

In the create of Game.js, I create my sprite and a tilemap:

...var map = this.game.add.tilemap('map');var layer = map.createLayer('Tile Layer 1');map.addTilesetImage('ground');map.addTilesetImage('star');        layer.resizeWorld();map.setCollisionBetween(1, 17);...this.ship = this.game.add.sprite(200, 200, 'ship');this.ship.animations.add('propulse', [1, 2, 3]);this.game.physics.p2.enable(this.ship, false);this.ship.body.addPolygon({}, 30, 35  ,  0, 35  ,  14, 5);this.ship.body.onBeginContact.add(this.hitWall, this);...

 

hitWall is not called. I have tried using a simple function but same issue. If you need more information, please ask.

 

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