MaximeC Posted October 29, 2014 Share Posted October 29, 2014 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 comment Share on other sites More sharing options...
lewster32 Posted October 29, 2014 Share Posted October 29, 2014 Can we see the part where you define hitWall? I'm pretty sure this will be a scope issue. Link to comment Share on other sites More sharing options...
MaximeC Posted October 29, 2014 Author Share Posted October 29, 2014 hitWall is defined the same way as create:SpaceShip.Game.prototype = { create: function() {... }, hitWall: function(wall) {... }};But I have also tried to define hitWall as a global function and also directly in onBeginContact. Link to comment Share on other sites More sharing options...
MaximeC Posted October 29, 2014 Author Share Posted October 29, 2014 The line:this.game.physics.startSystem(Phaser.Physics.P2JS);Should be in Game.js. I found the problem by noticing that the gravity was not taken into consideration either. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts