use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class FreetypeFontLoader method loadSync.
@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, FreeTypeFontLoaderParameter parameter) {
if (parameter == null)
throw new RuntimeException("FreetypeFontParameter must be set in AssetManager#load to point at a TTF file!");
FreeTypeFontGenerator generator = manager.get(parameter.fontFileName + ".gen", FreeTypeFontGenerator.class);
BitmapFont font = generator.generateFont(parameter.fontParameters);
return font;
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class BitmapFontLoader method loadSync.
@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) {
if (parameter != null && parameter.atlasName != null) {
TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class);
String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString();
AtlasRegion region = atlas.findRegion(name);
if (region == null)
throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName);
return new BitmapFont(file, region);
} else {
int n = data.getImagePaths().length;
Array<TextureRegion> regs = new Array(n);
for (int i = 0; i < n; i++) {
regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class)));
}
return new BitmapFont(data, regs, true);
}
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class DragAndDropTest method create.
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
final Skin skin = new Skin();
skin.add("default", new LabelStyle(new BitmapFont(), Color.WHITE));
skin.add("badlogic", new Texture("data/badlogic.jpg"));
Image sourceImage = new Image(skin, "badlogic");
sourceImage.setBounds(50, 125, 100, 100);
stage.addActor(sourceImage);
Image validTargetImage = new Image(skin, "badlogic");
validTargetImage.setBounds(200, 50, 100, 100);
stage.addActor(validTargetImage);
Image invalidTargetImage = new Image(skin, "badlogic");
invalidTargetImage.setBounds(200, 200, 100, 100);
stage.addActor(invalidTargetImage);
DragAndDrop dragAndDrop = new DragAndDrop();
dragAndDrop.addSource(new Source(sourceImage) {
public Payload dragStart(InputEvent event, float x, float y, int pointer) {
Payload payload = new Payload();
payload.setObject("Some payload!");
payload.setDragActor(new Label("Some payload!", skin));
Label validLabel = new Label("Some payload!", skin);
validLabel.setColor(0, 1, 0, 1);
payload.setValidDragActor(validLabel);
Label invalidLabel = new Label("Some payload!", skin);
invalidLabel.setColor(1, 0, 0, 1);
payload.setInvalidDragActor(invalidLabel);
return payload;
}
});
dragAndDrop.addTarget(new Target(validTargetImage) {
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
getActor().setColor(Color.GREEN);
return true;
}
public void reset(Source source, Payload payload) {
getActor().setColor(Color.WHITE);
}
public void drop(Source source, Payload payload, float x, float y, int pointer) {
System.out.println("Accepted: " + payload.getObject() + " " + x + ", " + y);
}
});
dragAndDrop.addTarget(new Target(invalidTargetImage) {
public boolean drag(Source source, Payload payload, float x, float y, int pointer) {
getActor().setColor(Color.RED);
return false;
}
public void reset(Source source, Payload payload) {
getActor().setColor(Color.WHITE);
}
public void drop(Source source, Payload payload, float x, float y, int pointer) {
}
});
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class ETC1Test method create.
@Override
public void create() {
font = new BitmapFont();
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
controller = new OrthoCamController(camera);
Gdx.input.setInputProcessor(controller);
Pixmap pixmap = new Pixmap(32, 32, Format.RGB565);
pixmap.setColor(1, 0, 0, 1);
pixmap.fill();
pixmap.setColor(0, 1, 0, 1);
pixmap.drawLine(0, 0, 32, 32);
pixmap.drawLine(0, 32, 32, 0);
ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap);
pixmap.dispose();
pixmap = ETC1.decodeImage(encodedImage, Format.RGB565);
encodedImage.dispose();
img1 = new Texture(pixmap);
img2 = new Texture("data/test.etc1");
batch = new SpriteBatch();
pixmap.dispose();
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class FilesTest method create.
@Override
public void create() {
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
batch = new SpriteBatch();
if (Gdx.files.isExternalStorageAvailable()) {
message += "External storage available\n";
message += "External storage path: " + Gdx.files.getExternalStoragePath() + "\n";
try {
InputStream in = Gdx.files.internal("data/cube.obj").read();
StreamUtils.closeQuietly(in);
message += "Open internal success\n";
} catch (Throwable e) {
message += "Couldn't open internal data/cube.obj\n" + e.getMessage() + "\n";
}
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external("test.txt").write(false)));
out.write("test");
message += "Write external success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open externalstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't write externalstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(out);
}
try {
InputStream in = Gdx.files.external("test.txt").read();
StreamUtils.closeQuietly(in);
message += "Open external success\n";
} catch (Throwable e) {
message += "Couldn't open internal externalstorage/test.txt\n" + e.getMessage() + "\n";
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(Gdx.files.external("test.txt").read()));
if (!in.readLine().equals("test"))
message += "Read result wrong\n";
else
message += "Read external success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open externalstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't read externalstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(in);
}
if (!Gdx.files.external("test.txt").delete())
message += "Couldn't delete externalstorage/test.txt";
} else {
message += "External storage not available";
}
if (Gdx.files.isLocalStorageAvailable()) {
message += "Local storage available\n";
message += "Local storage path: " + Gdx.files.getLocalStoragePath() + "\n";
BufferedWriter out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(Gdx.files.local("test.txt").write(false)));
out.write("test");
message += "Write local success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open localstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't write localstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(out);
}
try {
InputStream in = Gdx.files.local("test.txt").read();
StreamUtils.closeQuietly(in);
message += "Open local success\n";
} catch (Throwable e) {
message += "Couldn't open localstorage/test.txt\n" + e.getMessage() + "\n";
}
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(Gdx.files.local("test.txt").read()));
if (!in.readLine().equals("test"))
message += "Read result wrong\n";
else
message += "Read local success\n";
} catch (GdxRuntimeException ex) {
message += "Couldn't open localstorage/test.txt\n";
} catch (IOException e) {
message += "Couldn't read localstorage/test.txt\n";
} finally {
StreamUtils.closeQuietly(in);
}
try {
byte[] testBytes = Gdx.files.local("test.txt").readBytes();
if (Arrays.equals("test".getBytes(), testBytes))
message += "Read into byte array success\n";
else
fail();
} catch (Throwable e) {
message += "Couldn't read localstorage/test.txt\n" + e.getMessage() + "\n";
}
if (!Gdx.files.local("test.txt").delete())
message += "Couldn't delete localstorage/test.txt";
}
try {
testClasspath();
testInternal();
testExternal();
testAbsolute();
testLocal();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
Aggregations