I'm a complete newbie in Phaser, and I've been having this problem for the last couple of days. Basically, I want my player to collide with the CollisionsLayer in my .json tilemap, but it doesn't work and the player goes right through. I have tried multiple versions of Phaser and none of them seem to work. Here's my code:
<!DOCTYPE html>
<html>
<head>
<title>RPG Game</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.3.0/phaser.min.js"></script>
</head>
<body>
<script>
var game = new Phaser.Game(1000,600,Phaser.AUTO,'',{preload: preload, create: create, update: update});
function preload() {
game.load.tilemap('level', 'assets/level1.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('tiles', 'assets/tiles.png');
game.load.image('player', 'assets/star.png');
}
var map;
var backgroundLayer;
var collisionLayer;
var player;
var cursors;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
map = game.add.tilemap('level');
map.addTilesetImage('tiles');
backgroundLayer = map.createLayer("BackgroundLayer");
collisionLayer = map.createLayer("CollisionLayer");
map.setCollisionBetween(1,80);
backgroundLayer.resizeWorld();
player = game.add.sprite(200,200,'player');
game.physics.enable(player);
game.camera.follow(player);
cursors = game.input.keyboard.createCursorKeys();
}
function update() {
game.physics.arcade.collide(player, collisionLayer);
player.body.velocity.x = 0;
player.body.velocity.y = 0;
if (cursors.right.isDown) {
player.body.velocity.x = 200;
}
else if (cursors.left.isDown) {
player.body.velocity.x = -200;
}
else if (cursors.up.isDown) {
player.body.velocity.y = -200;
}
else if (cursors.down.isDown) {
player.body.velocity.y = 200;
}
}
</script>
</body>
</html>
The tilemap does load and I am able to move but I just don't collide with any tiles on the collision layer. Thanks in advance.