Jump to content

Strange tilemap copy/paste behaviour


Nepoxx
 Share

Recommended Posts

In my quest to have a dynamically loading tilemap, I am trying to use the copy/paste function provided by the tilemaps to copy tiles from one map to a distinct map (the original one is not rendered, it simply serves as a "tile data store" for now (later on it'll handled by  a server)).

 

For some reason, I can copy data from my first tilemap to the second one, but the location where it is pasted is not right at all. I even have to provide negative numbers in the paste function to align them correctly

    var cellSize = 4;    map = game.add.tilemap('map'); // Loaded from JSON above    /* Map renderer */    renderedMap = game.add.tilemap();    renderedMap.addTilesetImage('magecity', undefined, undefined, undefined, undefined, undefined, 1); // I want the GID to start at 1    renderedMap.setCollisionByExclusion([2, 237, 335]);    ground = renderedMap.create('ground', 3 * cellSize, 3 * cellSize, 32, 32);    ground.resizeWorld();        cells = map.copy(0, 4, cellSize, cellSize);          renderedMap.paste(0, 0, cells, ground); //Here the data pasted is NOT at (0,0) (It looks like it was pasted at (0,8)) 

As usual, thanks !

.

Link to comment
Share on other sites

My apologies for the spam, from Tileset.js

        //  Find out the difference between tileblock[1].x/y and x/y and use it as an offset, as it's the top left of the block to paste        var diffX = tileblock[1].x - x;        var diffY = tileblock[1].y - y;

it would seem that the parameters x and y are offset from the original copy. This is not consistent with (my understanding of) the documentation which states:

paste(x, y, tileblock, layer)
 
Pastes a previously copied block of tile data into the given x/y coordinates. Data should have been prepared with Tilemap.copy.

 

 

I don't understand why paste would take in an offset. I want to paste the block of tiles at location (x,y). I came up with the following workaround, but it's not so pretty:

cells = map.copy(0, 4, cellSize, cellSize);//These are the coords where I want to paste the block I just copiedcells[1].x = destinationX;cells[1].y = destinationY;renderedMap.paste(0,0,cells,ground);

Edit: actually, this doesn't even work.

 

Is my understanding of copy/paste or tilemaps in general wrong?

Link to comment
Share on other sites

Just a little bump.

 

I've been thinking of implementing an "absolutePaste" and then submitting a pull request for that, is that a good idea? I would have it paste the tile date at the given coordinates, NOT relative to the given coordinate (the given coord would be the top left corner of the data to paste).

 

Thoughts?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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