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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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