Sekushi Posted August 10, 2014 Share Posted August 10, 2014 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 More sharing options...
valueerror Posted August 11, 2014 Share Posted August 11, 2014 maybe you should define the layer in setcollisionbetween (from the docs):setCollisionBetween(start, stop, collides, layer, recalculate)or try the other way:map.setCollisionByExclusion([0],true, groundLayer);this of course should happen AFTER you setup the groundLayer Link to comment Share on other sites More sharing options...
Recommended Posts