-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprites.pde
56 lines (42 loc) · 1.22 KB
/
Sprites.pde
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
class SpriteFactory
{
HashMap<String, PShape> sprites;
void load(String sprite_folder)
{
sprites = new HashMap<String, PShape>();
File dir = new File(sprite_folder);
File[] files = dir.listFiles();
for (File f : files)
{
if (f.isDirectory() || !f.getName().endsWith("svg"))
continue;
String name = f.getName().split("\\.")[0];
PShape p = loadShape(f.getAbsolutePath());
p.scale(1f/p.getWidth(), 1f/p.getHeight());
p.setName(name);
sprites.put(name, p);
}
}
PShape get(String name)
{
if (!sprites.containsKey(name))
{
println("No sprite found with name '" + name + "'. Using null sprite."); //<>//
return sprites.get("null");
}
return sprites.get(name);
}
PShape get(StringList names)
{
PShape retval = createShape(GROUP);
retval.setName("_GROUP");
for (String name : names)
retval.addChild(get(name)); //<>//
return retval;
}
boolean has_sprite(String name) { return sprites.containsKey(name); }
StringList get_sprite_names()
{
return new StringList(sprites.keySet());
}
}