-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassets.js
More file actions
61 lines (58 loc) · 1.59 KB
/
assets.js
File metadata and controls
61 lines (58 loc) · 1.59 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
var atlas = [{
src: Image,
images: [{
name: "imageName",
x: 0,
y: 0,
width: 16,
height: 16
}]
}];
export class Asset{
constructor(atlas = 0, name = "item", x = 0, y = 0, size = 1){
this.atlas = atlas;
this.name = name;
this.x = x;
this.y = y;
this.size = size;
let source;
}
getInfo(){
return {name:this.name, position:{x:this.x, y:this.y}, radius:{width:this.source.width, height:this.source.height}};
}
}
export function asepriteConfig(atlasImgs=[], json=[]){
var i = 0;
for (let index = 0; index < atlasImgs.length - 1; index++) {
atlas.push({src:null, images:[{}]});
}
atlasImgs.forEach(a => {
var img = new Image();
img.src = a;
atlas[i].src = img;
try {
json[i].meta.slices.forEach(s => {
var img = {
name: s.name,
x: s.keys[0].bounds.x,
y: s.keys[0].bounds.y,
width: s.keys[0].bounds.w,
height: s.keys[0].bounds.h
}
atlas[i].images.push(img);
})
} catch (error) {
console.log(error);
}
i++;
})
console.log(atlas);
}
export const createAsset = (asset, ctx) =>{
var a = atlas[asset.atlas].images.find((e)=>e.name === asset.name);
if(a){
ctx.drawImage(atlas[asset.atlas].src, a.x,a.y,a.width,a.height,asset.x,asset.y,a.width*asset.size,a.height*asset.size);
asset.source = a;
}
return asset;
}