mirror of
https://github.com/wassname/phaser.git
synced 2026-10-02 12:30:54 +08:00
Tilemap - reverse diffX and diffY equations in Tilemap#paste.
This commit is contained in:
1 parent
16fa37081f
commit
b0f4ac3bcc
3 files changed
+78
-2
No files matched your search
@@ -918,8 +918,8 @@ Phaser.Tilemap.prototype = {
|
||||
}
|
||||
|
||||
// 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;
|
||||
var diffX = x - tileblock[1].x;
|
||||
var diffY = y - tileblock[1].y;
|
||||
|
||||
for (var i = 1; i < tileblock.length; i++)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>QUnit Example</title>
|
||||
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
|
||||
<script>
|
||||
var Phaser = {};
|
||||
</script>
|
||||
<script src="../src/tilemap/Tilemap.js"></script>
|
||||
<script src="../src/tilemap/TilemapParser.js"></script>
|
||||
<script src="../src/tilemap/Tileset.js"></script>
|
||||
<script src="../src/tilemap/Tile.js"></script>
|
||||
<script src="../test/tilemap/Tilemap.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Created by Brett on 08/02/14.
|
||||
*/
|
||||
var game,
|
||||
tilemap,
|
||||
mockedMap;
|
||||
|
||||
module("Tilemap", {
|
||||
setup: function() {
|
||||
mockedMap = JSON.parse('{"url":"assets/maps/desert.json","data":{"height":40,"layers":[{"data":[30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,14,15,16,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,30,30,30,30,30,30,31,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,14,15,16,30,31,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,14,15,16,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,31,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,31,22,23,24,30,30,30,30,30,30,30,30,32,30,30,32,30,30,30,30,30,30,31,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,1,3,30,30,31,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,25,26,26,26,26,26,26,26,26,26,26,26,27,30,9,11,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30,9,11,30,30,30,30,6,7,7,7,8,30,46,30,30,30,30,30,30,30,30,40,30,30,30,30,33,34,36,42,37,34,34,34,34,34,34,34,35,30,9,11,30,30,30,30,14,15,15,15,16,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,35,30,33,34,34,34,34,34,34,34,35,30,9,11,30,30,30,30,14,15,15,15,12,8,30,30,30,30,30,30,30,30,30,30,30,38,30,30,33,34,35,31,33,34,34,34,34,34,34,34,35,30,9,11,30,30,30,30,22,23,5,15,15,16,30,30,30,30,30,30,30,30,48,38,30,30,30,30,33,34,44,26,45,34,34,34,34,34,34,34,35,30,9,11,30,30,30,30,30,30,14,15,15,16,30,30,30,30,30,30,40,30,30,30,40,30,30,30,33,34,34,34,34,34,34,34,36,42,37,34,35,30,9,11,30,30,30,30,30,31,22,23,23,24,30,30,30,40,30,30,30,30,40,38,30,30,38,30,41,42,42,42,42,37,34,34,44,26,45,34,35,30,9,11,30,30,30,30,30,30,30,30,30,30,30,30,30,30,39,30,30,30,38,30,40,30,30,30,30,30,30,30,30,41,42,42,42,42,42,42,43,30,9,11,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,9,11,30,30,30,31,30,30,30,30,30,30,30,30,30,7,7,8,1,2,2,2,2,2,3,30,30,30,1,2,2,2,2,2,2,2,2,2,2,2,29,11,30,30,30,30,31,30,31,30,30,30,30,30,30,15,15,16,9,10,10,10,10,10,11,30,30,30,9,10,10,10,10,10,10,10,10,10,10,10,10,11,30,30,30,31,30,30,30,30,30,30,30,30,30,23,23,24,17,18,18,18,18,18,19,30,30,30,17,18,18,18,18,18,18,18,18,18,18,18,18,19,30,30,30,30,30,30,32,30,30,30,30,30,30,30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,30,30,32,31,30,30,30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,30,30,25,26,26,26,26,26,26,26,26,26,26,26,27,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,46,30,33,34,34,34,34,34,34,34,34,36,42,37,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,35,48,33,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,30,47,33,34,34,34,34,34,34,34,34,35,48,33,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,39,30,30,30,33,34,34,34,34,34,34,34,34,35,48,33,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,44,26,45,35,30,30,30,30,30,30,39,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,47,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,48,30,30,30,30,30,39,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,33,34,34,34,34,34,34,34,34,34,34,34,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,41,42,42,42,42,42,42,42,42,42,42,42,43,30,30,30,38,30,38,30,30,30,30,32,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,38,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,40,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,38,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,40,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,30,30,30,30,40,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,30,31,30,30,30,30,30,30,30,30,30,30,30,6,7,7,7,7,8,30,30,30,30,30,30,30,40,30,40,30,30,30,30,30,30,30,30,30,30,30,30,30,30,32,30,30,26,26,26,26,26,26,26,45,34,34,34,34,44,27,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,34,34,34,34,34,34,34,34,34,34,34,34,34,35,30,30,30,30,40,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,34,34,34,34,34,34,34,34,34,34,34,34,34,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,34,34,34,34,34,34,34,34,34,34,34,34,34,35,30,30,30,32,30,30,30,30,30,30,30,30,32,30,30,30,30,30,30,30,30,30,30,30,30,30,34,34,34,34,34,34,34,34,34,34,34,34,34,35,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30],"height":40,"name":"Ground","opacity":1,"type":"tilelayer","visible":true,"width":40,"x":0,"y":0}],"orientation":"orthogonal","properties":{},"Line truncated
|
||||
game = {
|
||||
cache: {
|
||||
getTilemapData: function (key) {
|
||||
return mockedMap;
|
||||
}
|
||||
}
|
||||
};
|
||||
tilemap = new Phaser.Tilemap(game);
|
||||
},
|
||||
teardown: function() {
|
||||
mockedMap = null;
|
||||
game = null;
|
||||
tilemap = null;
|
||||
}
|
||||
});
|
||||
|
||||
test( "Tilemap#copy", function() {
|
||||
var result = tilemap.copy(0, 0, 2, 2);
|
||||
equal( result.length, 5 );
|
||||
equal( result[0].x, 0 );
|
||||
equal( result[0].y, 0 );
|
||||
equal( result[0].width, 2 );
|
||||
equal( result[0].height, 2 );
|
||||
});
|
||||
|
||||
test("Tilemap#paste", function() {
|
||||
var result = tilemap.copy(0, 0, 2, 2);
|
||||
|
||||
var currentTilemapLayer = tilemap.layers[tilemap.currentLayer];
|
||||
notEqual(currentTilemapLayer.dirty, true);
|
||||
equal(currentTilemapLayer.data[0][0].index, 30);
|
||||
|
||||
result[1].index = 99; // this changes both the index in the result and in the tilemap even before paste
|
||||
// ... probably not desired behaviour
|
||||
|
||||
tilemap.paste(0, 0, result);
|
||||
equal(currentTilemapLayer.dirty, true);
|
||||
equal(currentTilemapLayer.data[0][0].index, 99);
|
||||
|
||||
currentTilemapLayer.dirty = false;
|
||||
|
||||
tilemap.paste(10, 0, result);
|
||||
equal(currentTilemapLayer.dirty, true);
|
||||
equal(currentTilemapLayer.data[0][10].index, 99);
|
||||
});
|
||||
Reference in new issue
Block a user