Jump to content

[P2JS] Problem with Collision. [FIXED]


Staafsak
 Share

Recommended Posts

Hello people,
I have a problem with collision in my demo game. (800x800 pixels) It won't allow me to walk around.
also there is no worldbounds because it doesn't work too.
 

I have checked the console in different browser, but theres no error.
 

EDIT: Yes, I have been checking out the examples etc, but got no clue what am doing wrong.
 

window.RPG.Game.Main = function () {    this.cursors = null;};window.RPG.Game.Main.prototype.preload = function() {	// World map	this.load.tilemap('demo-map', 'assets/tilemaps/demo-map.json', null, Phaser.Tilemap.TILED_JSON);	// Sprites	// {1} = Width  frame	// {2} = Height frame	// {3} = how many frames - leave blank if frames fill up the entire PNG.	this.load.spritesheet('player', '/assets/sprites/chara0.gif', 32, 32);	// Images	// {1} = Image name (in the map.json)	// {2} = Image path (on the server)	this.load.image('items', '/assets/sprites/items.png');	this.load.image('font0', '/assets/sprites/font0.png');	this.load.image('icon0', '/assets/sprites/icon0.png');	this.load.image('tiles', 'assets/sprites/map1.gif');	this.load.image('npcs', '/assets/sprites/npcs.png');	this.load.image('pad', '/assets/sprites/pad.png');	this.load.image('x', 'assets/sprites/x.png');};window.RPG.Game.Main.prototype.create = function () {	//1 Physics	this.game.physics.startSystem(Phaser.Physics.P2JS);    // Camera controls    this.cursors = this.input.keyboard.createCursorKeys();    this.game.world.setBounds(-800, -800, 1600, 1600);		// Scaling the Camera to better zoom	this.game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;    // Define map variables    var map, backgroundLayer, blockedLayer;    // Load the map and objects    map = this.add.tilemap('demo-map');	map.addTilesetImage('map1', 'tiles');	map.addTilesetImage('x', 'x');	map.createFromObjects('objectLayer');    // Render the background layer    backgroundLayer = map.createLayer('backgroundLayer');    backgroundLayer.resizeWorld();    // Render the blocked layer    blockedLayer = map.createLayer('blockedLayer');    blockedLayer.resizeWorld();    // Render the object layer    map.createFromObjects('objectLayer');	blockedLayer.resizeWorld();		// Create player	this.player = this.game.add.sprite(this.game.world.centerX,this.game.world.centerY, 'player');		// 0 = down	// 1 = up	// 2 = left	// 3 = right	this.player.direction = 0	// Animate player	// 0, 1, 2, = which frames	// 5 = frequency of change	this.player.animations.add('walkD', [1, 0, 2], 5, true);	this.player.animations.add('walkL', [9, 10, 11], 5, true);	this.player.animations.add('walkR', [18, 19, 20], 5, true);	this.player.animations.add('walkU', [27, 28, 29], 5, true);		// Camera follows player position	this.game.camera.follow(this.player);		//1 physics enable on player	//+ set body	//+ collide with world bounds	this.game.physics.p2.enable(this.player);	this.player.body.setCircle(28);	this.player.body.collideWorldBounds = true;	};window.RPG.Game.Main.prototype.update = function () {		//1 Stop moving on collision	this.player.body.setZeroVelocity();    // Movement code here};
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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