erest0r Posted July 5, 2016 Share Posted July 5, 2016 Hello again, i'm having a problem with my p2.body, it always goes off screen even setting world bounds, besides i'm using a tilemap (my p2.body isn't part of the tilemap), here is my code: module Ark_Annoying { export class Game extends Phaser.State { cursors: Phaser.CursorKeys; player: Phaser.Sprite; map: Phaser.Tilemap; level1: Phaser.TilemapLayer; create() { this.map = this.game.add.tilemap("level1"); this.map.addTilesetImage("blocks_tileset", "blocks"); this.level1 = this.map.createLayer("layer1"); this.level1.resizeWorld(); this.player = this.game.add.sprite(this.game.world.centerX, this.game.world.height - 24, "player"); this.player.anchor.setTo(0.5, 0.5); this.game.physics.p2.enable(this.player); this.game.physics.p2.setBoundsToWorld(true, true); this.cursors = this.game.input.keyboard.createCursorKeys(); } update() { this.player.body.setZeroVelocity(); if (this.cursors.left.isDown) this.player.body.velocity.x = -500; else if (this.cursors.right.isDown) this.player.body.velocity.x = 500; } } } I followed instructions in this link http://www.html5gamedevs.com/topic/5575-p2-not-colliding-with-world-bounds/ but it didn't work. I'll appreciate your help. I found this solution: I was calling this.game.phsycis.startSystem(Phaser.Physics.P2JS) in my Boot state, and changed to Game state, and started to work. Can somebody explain me why is this behaviour? Link to comment Share on other sites More sharing options...
Recommended Posts