Вопрос

I'm trying phaser and I created a Tiles Map with Tiled that I "imported" on phaser.

Everything works fine, the only problem is that I didn't find how I can fit the TilesMap (which is 60px bigger than the canvas) to the canvas. I looked all examples, but I found nothing at all.

Isn't the job of this function? layer.resizeWorld()

var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
var map;
var tileset;
var layer;
var player;
var cursors; 



function preload() {
    game.load.tilemap('map', 'assets/maps/map.json', null, Phaser.Tilemap.TILED_JSON);
    game.load.image('tiles', 'assets/tiles/tilesSheet.png');
}

function loadUpdate(){
}

function create() {
    map = game.add.tilemap('map');
    map.addTilesetImage('tilesSheet','tiles');
    layerGround = map.createLayer("Ground");
    layerObstacle = map.createLayer("Obstacle");     
    //  Un-comment this on to see the collision tiles
    // layer.debug = true;
    layerGround.resizeWorld();
}

function update() {
}

function render() {
}
Это было полезно?

Решение

layer.resizeWorld() will resize the Game World to match the size of your tilemap. It won't do anything to the Canvas object. Whatever size you give for your game in the Game constructor is the size the canvas will be created and displayed at. So in your example above it will make an 800x600 sized canvas.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top