Jump to content

Scaling TilemapLayer


Seanw265
 Share

Recommended Posts

  • 2 months later...

We had this code for scaling tilemaps in a recent game using Phaser 2.04 and it did work with Arcade physics.

 

Map.prototype.scaleTilemapData = function(name, scale) {    var tilemapData = this.game.cache.getTilemapData(name);    if(tilemapData.isScaled) { return; }    this.scaleTileWidthAndHeight(tilemapData, scale);    this.scaleTilesets(tilemapData, scale);    this.scaleObjectLayers(tilemapData, scale);    tilemapData.isScaled = true;};Map.prototype.scaleTileWidthAndHeight = function(tilemapData, scale) {    tilemapData.data.tilewidth *= scale;    tilemapData.data.tileheight *= scale;};Map.prototype.scaleTilesets = function(tilemapData, scale) {    var tilesets = tilemapData.data.tilesets,        l = tilesets.length,        tileset;    for(var i = 0; i < l; i++) {        tileset = tilesets[i];        tileset.imageheight *= scale;        tileset.imagewidth *= scale;        tileset.tileheight *= scale;        tileset.tilewidth *= scale;    }};Map.prototype.scaleObjectLayers = function(tilemapData, scale) {    var layers = tilemapData.data.layers,        l = layers.length,        layer;    for(var i = 0; i < l; i++) {        layer = layers[i];        if(Object.prototype.toString.call(layer.objects) === '[object Array]') {            layer.objects = this.scaleObjects(layer.objects, scale);        }    }};Map.prototype.scaleObjects = function(objects, scale) {    var l = objects.length,        object;    for(var i = 0; i < l; i++) {        object = objects[i];        object.x *= scale;        object.y *= scale;    }    return objects;};
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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