타일 맵이 1 레이어 만 플레이어와 올바르게 충돌합니다. 모든 예제를 통해 있었지만 여러 레이어에서 작동하지는 못합니다.PhaserJS 충돌 타일 맵이 작동하지 않습니다.
는 I는 13 층의 총 모든 JSON 데이터를 포함하는 1 tilemap을 가지고 있지만, 예를 들어 I은 플레이어가 다른 층과 충돌 및 다른 콜백을 할 싶습니다 3.
를 포함했다 , 예. 보행 거리를 벗어나서 항목을 집어들 수는 없지만 모두 1 spritemap/tilemap을 사용합니다.
var game = new Phaser.Game(1200, 780, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
this.load.tilemap('main_map', 'img here', null, Phaser.Tilemap.TILED_JSON);
this.load.image('sprite_map', 'img here');
this.load.image('player_image', 'img here');
}
var map;
var tileset;
var bLayer;
var wLayer;
var player;
var sLayer;
var cursors;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
// initiallize the tilemap
map = game.add.tilemap('main_map');
map.addTilesetImage('otherNew', 'sprite_map');
//draw the layers
bLayer = map.createLayer(0);
wLayer = map.createLayer(1);
sLayer = map.createLayer(2);
wLayer.resizeWorld();
player = game.add.sprite(600, 600, 'player_image');
game.physics.arcade.enable(player);
player.body.collideWorldBounds = true; // works
//game camera and movment keys here
}
function update() {
game.physics.arcade.collide(player, wLayer); // DOES NOT WORK
game.physics.arcade.collide(player, sLayer); // THIS WORKS
map.setCollision(1, true, wLayer); // DOES NOT WORK
map.setCollision(2, true, sLayer); // THIS WORKS
//movement here already works so didn't include
}
안녕하세요 제임스, 응답 주셔서 감사합니다. 이미 문제가 무엇인지 알아 냈습니다. 아래에서 심층적 인 답변을 게시 할 예정입니다. – Paddy