-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite-helper.html
132 lines (105 loc) · 2.45 KB
/
sprite-helper.html
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
<html>
<style>
canvas{
background-image: url("assets/player.png");
background-position: center;
background-size: 100% 100%;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<body>
<canvas id="canvas" width="128" height="448">
Your browser doesn't support canvas
</canvas>
</body>
<script>
var width = 32;
var height = 32;
function drawBox(x, y){
ctx.rect(x,y,width, height-0.5);
ctx.stroke();
}
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
var startX, startY;
ctx.strokeStyle = 'red';
ctx.lineWidth = 0.5;
var positions =
"0 = [0, 0]\n"+
"1 = [32, 0]\n"+
"2 = [64, 0]\n"+
"3 = [96, 0]\n"+
"4 = [0, 32]\n"+
"5 = [32, 32]\n"+
"6 = [64, 32]\n"+
"7 = [96, 32]\n"+
"8 = [0, 64]\n"+
"9 = [32, 64]\n"+
"10 = [64, 64]\n"+
"11 = [96, 64]\n"+
"12 = [0, 96]\n"+
"13 = [32, 96]\n"+
"14 = [64, 96]\n"+
"15 = [96, 96]\n"+
"16 = [0, 128]\n"+
"17 = [32, 128]\n"+
"18 = [64, 128]\n"+
"19 = [96, 128]\n"+
"20 = [0, 160]\n"+
"21 = [32, 160]\n"+
"22 = [64, 160]\n"+
"23 = [96, 160]\n"+
"24 = [0, 192]\n"+
"25 = [32, 192]\n"+
"26 = [64, 192]\n"+
"27 = [96, 192]\n"+
"28 = [0, 224]\n"+
"29 = [32, 224]\n"+
"30 = [64, 224]\n"+
"31 = [96, 224]\n"+
"32 = [0, 256]\n"+
"33 = [32, 256]\n"+
"34 = [64, 256]\n"+
"35 = [96, 256]\n"+
"36 = [0, 288]\n"+
"37 = [32, 288]\n"+
"38 = [64, 288]\n"+
"39 = [96, 288]\n"+
"40 = [0, 320]\n"+
"41 = [32, 320]\n"+
"42 = [64, 320]\n"+
"43 = [96, 320]\n"+
"44 = [0, 352]\n"+
"45 = [32, 352]\n"+
"46 = [64, 352]\n"+
"47 = [96, 352]\n"+
"48 = [0, 384]\n"+
"49 = [32, 384]\n"+
"50 = [64, 384]\n"+
"51 = [96, 384]\n"+
"52 = [0, 416]\n"+
"53 = [32, 416]\n"+
"54 = [64, 416]\n"+
"55 = [96, 416]\n"
;
var positionsArray = positions.split("\n");
ctx.clearRect (0, 0, can.width, can.height);
ctx.textAlign = 'start';
ctx.textBaseline='top';
ctx.fillStyle = "black";
var rx = /(\d+)\s*=\s*\[(\d+),\s*(\d+)\]/g;
for(const positionData of positionsArray)
{
var arr = rx.exec(positionData);
rx.lastIndex = 0;
if(arr == null) {
continue;
}
var key = arr[1];
var start_x = arr[2];
var start_y = arr[3];
ctx.fillText(key, start_x, start_y);
drawBox(start_x, start_y);
}
</script>
</html>