-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
123 lines (77 loc) · 2.51 KB
/
load.js
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
//load tileset
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//maps
var teste = new Array();
var xmlDoc= new Array();
for (coisa=0;coisa<9;coisa++){
teste[coisa]="mapa-corrigido.xml";
xmlhttp.open("GET",teste[coisa],false);
xmlhttp.send();
xmlDoc[coisa]=xmlhttp.responseXML;
}
var x=xmlDoc[0].getElementsByTagName("layers");
var i=0;
var layer =new Array();
var z = x[0].childNodes;
layerCount=z.length;
for (teste3=0; teste3<layerCount;teste3++){
layer[teste3]=(x[i].getElementsByTagName("layer")[teste3].childNodes[0].nodeValue);
}
var n = layer[1].split(",");
var auxilar=n[0].split(".");
var n1=auxilar[0];
var n2=auxilar[1];
///////////////////////////////////////////////////////////////////////////
//load screen
var canvas = document.getElementById('testCanvas');
var context = canvas.getContext('2d');
var ctx = canvas.getContext('2d');
context.fillStyle="#FF0000";
context.fillRect(0,0,150,75);
var imageObj = new Image();
var teste=0;
var teste2=0;
errorCount=0;
////aqui
var atributo=z[0].getAttribute('tileset');
preloadimages(['mage_city.png']).done(function(images){
alert('carregou');
})
var posX=7;//repetir para Y
var posY=7;
update();
function update(){
// alert(images.length)
var imagens =new Array();
imagens[0]='mage_city.png';
/////////
imageObj.src = imagens[0];
//imageObj.onload = function() { //verifica se carregou a imagen
for (teste3=0;teste3<layerCount;teste3++){ //seleciona a camada à desenhar
for (teste=posY; teste<25+posY;teste++){
for (teste2=posX; teste2<19+posX;teste2++){
var n = layer[teste3].split(",");
try {var auxilar=n[teste2+(teste*25)].split(".");}//25 precisa ser ajustado à valores negativos e de acordo com o tamanho horizontal do mapa
catch (error){ errorCount ++;}
var n1=auxilar[0];
var n2=auxilar[1];
/* if (n1==0){ //previne que o primeiro pixel seja diferente de transparente
if (n2==0){
n1=4; //posição x do novo transparente, default 4
n2=12;//posição y do novo transparente, default 12
}} */
context.drawImage(imageObj,n1*32,n2*32,32,32,(teste2*32)-(posX*32),(teste*32)-(posY*32),32,32); //verificar se esse metodo funciona em todos navegadores
//void drawImage( in nsIDOMElement image, in float sourceX, in float sourceY, in float sWidth, in float sHeigth, in float destinyX, in float destinyY, in float dwidth, in float dheigth);
}
}
}
//}
}
//)