Jump to content

Mario won't collide with tilemap layer


Sekushi
 Share

Recommended Posts

For some reason, Mario will just fall through the tilemap layer "Ground". Do I have the collision and physics set up correctly? I used the Starstruck example on the Phaser website, but to no avail. Thanks in advance guys!
var game = new Phaser.Game(320, 240, Phaser.AUTO, 'gameCanvas');var map;var tileset;var groundLayer;var mario;var cursorsvar playState = {	preload: function() {			game.load.tilemap('level01', 'assets/level01.json', null, Phaser.Tilemap.TILED_JSON);		game.load.image('tiles1', 'assets/mariotileset.png');		game.load.spritesheet('marioSheet', 'assets/marioSheet.png', 16, 25);	},		create: function() {			game.physics.startSystem(Phaser.Physics.ARCADE);		game.stage.backgroundColor = '#66DDFF';				map = game.add.tilemap('level01');		map.addTilesetImage('tileset', 'tiles1');		map.setCollisionBetween(136, 140);				groundLayer = map.createLayer('Ground');		groundLayer.resizeWorld();				game.physics.arcade.gravity.y = 350;				mario = game.add.sprite(200, 200, 'marioSheet');		game.physics.enable(mario, Phaser.Physics.ARCADE);		mario.body.collideWorldBounds = true;				mario.anchor.setTo(0.5, 1);		mario.animations.add('walk', [0, 1, 2, 1], 15, true);				cursors = game.input.keyboard.createCursorKeys();	},		update: function() {			game.physics.arcade.collide(mario, groundLayer);				mario.body.velocity.x = 0;				if (cursors.left.isDown) {					mario.animations.play('walk');			mario.scale.x = -1;			mario.body.velocity.x = -200;		}		else if (cursors.right.isDown) {					mario.animations.play('walk');			mario.scale.x = 1;			mario.body.velocity.x = 200;		}		else {					mario.animations.stop();		}	}};game.state.add('play', playState);game.state.start('play');

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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