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
|
package ch.asynk.zproject;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader.FreeTypeFontLoaderParameter;
public class Assets extends AssetManager implements Disposable
{
public static final String CORNER = "data/corner.png";
public static final String MAP_00 = "data/map_00.png";
public static final String LOADING = "data/loading.atlas";
public static final String FONT = "data/veteran-typewriter.ttf";
public static final String FONT_20 = "size20.ttf";
public static final String FONT_25 = "size25.ttf";
public static final String PATCH = "data/ui-patch.png";
private final FreeTypeFontLoaderParameter params20;
private final FreeTypeFontLoaderParameter params25;
public Assets()
{
super();
final FileHandleResolver resolver = new InternalFileHandleResolver();
setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
params20 = new FreeTypeFontLoaderParameter();
params20.fontFileName = FONT;
params20.fontParameters.size = 20;
params25 = new FreeTypeFontLoaderParameter();
params25.fontFileName = FONT;
params25.fontParameters.size = 25;
}
@Override public void dispose()
{
ZProject.debug("diagnostics:\n" + getDiagnostics() );
clear();
super.dispose();
}
public Texture getTexture(String assetName)
{
return get(assetName, Texture.class);
}
public NinePatch getNinePatch(String assetName, int left, int right, int top, int bottom)
{
return new NinePatch(get(assetName, Texture.class), left, right, top, bottom);
}
public TextureAtlas getAtlas(String assetName)
{
return get(assetName, TextureAtlas.class);
}
public BitmapFont getFont(String assetName)
{
return get(assetName, BitmapFont.class);
}
public void loadLoading()
{
load(LOADING, TextureAtlas.class);
}
public void unloadLoading()
{
unload(LOADING);
}
public void loadGame()
{
load(MAP_00, Texture.class);
load(CORNER, Texture.class);
load(PATCH, Texture.class);
load(FONT_20, BitmapFont.class, params20);
load(FONT_25, BitmapFont.class, params25);
}
public void unloadGame()
{
unload(MAP_00);
unload(CORNER);
unload(PATCH);
unload(FONT_20);
unload(FONT_25);
}
}
|