forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTilemap.js
More file actions
134 lines (99 loc) · 2.71 KB
/
Copy pathTilemap.js
File metadata and controls
134 lines (99 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Phaser.Tilemap = function (game, key) {
/**
* @property {Phaser.Game} game - Description.
*/
this.game = game;
/**
* @property {array} layers - Description.
*/
this.layers;
if (typeof key === 'string')
{
this.key = key;
this.layers = game.cache.getTilemapData(key).layers;
}
else
{
this.layers = [];
}
this.currentLayer = 0;
this.debugMap = [];
};
Phaser.Tilemap.CSV = 0;
Phaser.Tilemap.TILED_JSON = 1;
Phaser.Tilemap.prototype = {
create: function (name, width, height) {
var data = [];
for (var y = 0; y < height; y++)
{
data[y] = [];
for (var x = 0; x < width; x++)
{
data[y][x] = 0;
}
}
this.currentLayer = this.layers.push({
name: name,
width: width,
height: height,
alpha: 1,
visible: true,
tileMargin: 0,
tileSpacing: 0,
format: Phaser.Tilemap.CSV,
data: data
});
},
setLayer: function (layer) {
if (this.layers[layer])
{
this.currentLayer = layer;
}
},
createLayerSprite: function (tilset) {
// Creates a TilemapLayer which you can add to the display list
// Hooked to a specific layer within the map data
},
/**
* Set a specific tile with its x and y in tiles.
* @method putTile
* @param {number} x - X position of this tile.
* @param {number} y - Y position of this tile.
* @param {number} index - The index of this tile type in the core map data.
*/
putTile: function (x, y, index) {
if (x >= 0 && x < this.layers[this.currentLayer].width && y >= 0 && y < this.layers[this.currentLayer].height)
{
this.layers[this.currentLayer].data[y][x] = index;
}
},
dump: function () {
var txt = '';
var args = [''];
for (var y = 0; y < this.layers[this.currentLayer].height; y++)
{
for (var x = 0; x < this.layers[this.currentLayer].width; x++)
{
txt += "%c ";
if (this.layers[this.currentLayer].data[y][x] > 1)
{
if (this.debugMap[this.layers[this.currentLayer].data[y][x]])
{
args.push("background: " + this.debugMap[this.layers[this.currentLayer].data[y][x]]);
}
else
{
args.push("background: #ffffff");
}
}
else
{
args.push("background: rgb(0, 0, 0)");
}
}
txt += "\n";
}
args[0] = txt;
console.log.apply(console, args);
}
};