Java Examples for com.badlogic.gdx.graphics.g2d.BitmapFont
The following java examples will help you to understand the usage of com.badlogic.gdx.graphics.g2d.BitmapFont. These source code samples are taken from different open source projects.
Example 1
| Project: ShapeOfThingsThatWere-master File: Font.java View source code |
public BitmapFont get() { Texture fontTexture = new Texture(Gdx.files.internal("fonts/" + file + ".png")); fontTexture.setFilter(TextureFilter.Linear, TextureFilter.MipMapLinearLinear); TextureRegion fontRegion = new TextureRegion(fontTexture); return new BitmapFont(Gdx.files.internal("fonts/" + file + ".fnt"), fontRegion, false); }
Example 2
| Project: underkeep-master File: UITutorialSystem.java View source code |
@Override
protected void process(Entity e) {
Tutorial tutorial = tm.get(e);
if (tutorial.step == activeStep) {
String hint = tutorial.hint;
float a = 1;
Pos pos = pm.get(e);
BitmapFont.TextBounds bounds = fontManager.font.getBounds(hint);
float x = pos.x + bm.get(e).cx() - (bounds.width / 2);
float y = pos.y + bm.get(e).maxy + 15;
// clamp to screen.
if (x + bounds.width >= cameraSystem.getPixelWidth())
x = cameraSystem.getPixelWidth() - 4 - bounds.width;
if (y + bounds.height >= cameraSystem.getPixelHeight())
x = cameraSystem.getPixelHeight() - 4 - bounds.height;
if (y < 0)
y = 0;
if (x < 0)
x = 0;
batch.setProjectionMatrix(cameraSystem.guiCamera.combined);
batch.begin();
batch.setColor(1f, 1f, 1f, a);
batch.draw(assetSystem.get("hint-bg").getKeyFrame(0), x - 2, y - 2, (int) (bounds.width + 4), (int) (bounds.height + 4));
fontManager.font.setColor(1f, 1f, 1f, a);
fontManager.font.draw(batch, hint, (int) x, (int) y + 5);
batch.draw(assetSystem.get("clickme").getKeyFrame(age * 2f, true), pos.x - 4 + bm.get(e).cx(), pos.y + bm.get(e).cy() + 4);
batch.end();
Clickable clickable = cm.get(e);
if (clickable.clicked) {
activeStep++;
}
}
}Example 3
| Project: THG-master File: DefaultTurnPageStage.java View source code |
@Override
public void setNextDayStr(String dayStr) {
disBuffer = THG.getFont(dayStr, 40, Color.BLACK);
if (dayStrLabel == null) {
dayStrLabel = new Label(dayStr, new Label.LabelStyle((BitmapFont) disBuffer, Color.BLACK));
dayStrLabel.setSize(300 * org.thg.ui.Config.scaleX, 100 * org.thg.ui.Config.scaleY);
addActor(dayStrLabel);
} else {
dayStrLabel.setText(dayStr);
dayStrLabel.getStyle().font = (BitmapFont) disBuffer;
}
}Example 4
| Project: Crazy-Driver-VideoGame-master File: CrazyDriver.java View source code |
@Override
public void create() {
configurationManager = new ConfigurationManager();
batch = new SpriteBatch();
font = new BitmapFont();
// Crea la cámara y define la zona de visión del juego (toda la pantalla)
camera = new OrthographicCamera();
camera.setToOrtho(false, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
camera.update();
setScreen(new MainMenuScreen(this));
}Example 5
| Project: JDialogue-master File: Assets.java View source code |
public static void load() {
fontDistanceFieldShader = new ShaderProgram(Gdx.files.internal("assets/font/font.vert"), Gdx.files.internal("assets/font/font.frag"));
if (!fontDistanceFieldShader.isCompiled()) {
Gdx.app.error("fontShader", "compilation failed:\n" + fontDistanceFieldShader.getLog());
}
Texture fontTexture = new Texture(Gdx.files.internal("assets/font/consolas.png"), true);
fontTexture.setFilter(TextureFilter.MipMapLinearLinear, TextureFilter.Linear);
consolasFont = new BitmapFont(Gdx.files.internal("assets/font/consolas.fnt"), new TextureRegion(fontTexture), false);
Gdx.app.log("Assets", "Finished loading assets");
}Example 6
| Project: practicos-master File: Juego.java View source code |
@Override
public void create() {
// load the drop sound effect and the rain background "music"
rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));
fuente = new BitmapFont();
// start the playback of the background music immediately
rainMusic.setLooping(true);
rainMusic.play();
// create the camera and the SpriteBatch
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
batch = new SpriteBatch();
//CREO BALDES Y GOTAS
getBalde().CreateBalde();
getBalde2().CreateBalde();
getBalde2().SetPlayer2();
arrayDrop = new Array<Drop>();
spawnDrop();
}Example 7
| Project: RollOverSphere---a-simple-libgdx-game-master File: IntroScene.java View source code |
@Override
public void update(ISceneManager sceneManager, float deltaTime) {
GameHelper.clearScreen();
GameHelper.setProjectionFor2D(spriteBatch, 1920, 1080);
spriteBatch.begin();
sceneManager.getGameManager().getStars().update(deltaTime);
sceneManager.getGameManager().getStars().draw(spriteBatch);
spriteBatch.end();
BitmapFont font = gameManager.getBitmapFont();
if (!isGameChoosen) {
float angle = Mathf.lerp(359.0f, 0.0f, timer * 0.45f);
float titleScale = Mathf.lerp(4.0f, 1.0f, timer * 0.5f);
// every two seconds all colors in texture are rotated
float ntimer = (timer - (int) Math.max(timer - 0, 0f)) / 1.0f;
float npos = (int) Mathf.lerp(1f, 10f, ntimer) / 10.0f;
for (int i = 0; i < titleDrawers.length; ++i) {
MyFontDrawer fd = titleDrawers[i];
if (fd != null) {
fd.setUVMinMaxScrollV(textureRegionForTitle, npos, 0.3f);
fd.idt().translate(titleXPos[i], 800, 0.0f).scale(titleScale, titleScale, 0.0f).rotateAround(0.0f, 0.0f, 1.0f, angle);
}
}
myFontDrawerBatch.draw(gameManager.getShader("region"), textureRegionForTitle.getTexture());
GameHelper.setProjectionFor2D(spriteBatch, 1920, 1080);
spriteBatch.begin();
font.setScale(0.6f);
font.setColor(Color.WHITE);
font.draw(spriteBatch, creditsText, creditsPos, 180);
creditsPos -= 200.0f * deltaTime;
if (creditsPos < -font.getBounds(creditsText).width - 20.0f) {
creditsPos = 1920;
}
buttons.draw(spriteBatch);
// draw textButtons
for (TextButton tb : gameTypeButtons) {
tb.draw(spriteBatch, font);
}
} else // if game choosen second menu show
{
GameHelper.setProjectionFor2D(spriteBatch, 1920, 1080);
spriteBatch.begin();
float scale = Mathf.lerp(0.0f, 1.0f, gameChoosenTimer * 4f);
Sprite overlaySprite = sceneManager.getGameManager().getOverlaySprite(1.0f, 0.95f);
overlaySprite.setScale(scale);
overlaySprite.draw(spriteBatch);
if (scale == 1.0f) {
for (TextButton tb : difficultyTypeButtons) {
tb.draw(spriteBatch, font);
}
}
gameChoosenTimer += deltaTime;
}
spriteBatch.end();
timer += deltaTime;
}Example 8
| Project: SkiFun-master File: SkiFun.java View source code |
@Override
public void create() {
batcher = new SpriteBatch();
textOverPlayers = new BitmapFont(Gdx.files.internal("data/hobo.fnt"), Gdx.files.internal("data/hobo.png"), false, false);
Settings.load();
Assets.load();
// Load the TournamentsCore if we have a valid implementation of it
if (this.tournaments != null) {
NextpeerPlugin.load(this.tournaments);
}
setScreen(new MainScreen(this));
fps = new FPSLogger();
}Example 9
| Project: skuttande-nyan-cat-master File: FontManager.java View source code |
public static void init() {
fontTexture = new Texture(Gdx.files.internal("fonts/ConsolaMono-Bold.png"));
fontTexture.setFilter(TextureFilter.Linear, TextureFilter.MipMapLinearLinear);
TextureRegion fontRegion = new TextureRegion(fontTexture);
consolaMonoBold = new BitmapFont(Gdx.files.internal("fonts/ConsolaMono-Bold.fnt"), fontRegion, false);
consolaMonoBoldHalf = new BitmapFont(Gdx.files.internal("fonts/ConsolaMono-Bold.fnt"), fontRegion, false);
consolaMonoBoldHalf.scale(0.5f);
}Example 10
| Project: Illarion-Java-master File: GdxFontManager.java View source code |
@Nonnull
@Override
protected Font buildFont(@Nonnull String fntRef, @Nonnull String imageRoot, @Nullable Font outlineFont) throws IOException {
String imageName = getImageName(fntRef);
GdxTexture imageTexture = (GdxTexture) textureManager.getTexture(imageRoot, imageName);
if (imageTexture == null) {
throw new IOException("Failed to load required image: " + imageRoot + imageName);
}
GdxFont gdxOutlineFont = (outlineFont instanceof GdxFont) ? (GdxFont) outlineFont : null;
return new GdxFont(new BitmapFont(files.internal(fntRef), imageTexture.getTextureRegion(), true), gdxOutlineFont);
}Example 11
| Project: jcubicworld-master File: DebugHelper.java View source code |
/**
* Renders a minecraft like debug screen.
*
* @param camera
*/
public static void renderDebugInformation(PerspectiveCamera camera, CubicWorldClient client) {
// Init
if (spriteBatch == null) {
spriteBatch = new SpriteBatch();
font = new BitmapFont();
fpsCounterStack = new LinkedList<Integer>();
drawcallCounterStack = new LinkedList<Integer>();
upstreamBytesStack = new LinkedList<Integer>();
downstreamBytesStack = new LinkedList<Integer>();
}
// Update information stacks every 20th frame
if (Gdx.graphics.getFrameId() % 2 == 0) {
// Fps counter
fpsCounterStack.addLast(new Integer(Gdx.graphics.getFramesPerSecond()));
// More than 120 in there?
if (fpsCounterStack.size() > 120) {
fpsCounterStack.removeFirst();
}
}
// Networking update
upstreamBytesStack.addLast(client.getBytesUpstream());
// More than 120 in there?
if (upstreamBytesStack.size() > 120) {
upstreamBytesStack.removeFirst();
}
downstreamBytesStack.addLast(client.getBytesDownstream());
// More than 120 in there?
if (downstreamBytesStack.size() > 120) {
downstreamBytesStack.removeFirst();
}
// Drawcall counter update
drawcallCounterStack.addLast(new Integer(GLProfiler.drawCalls));
// More than 120 in there?
if (drawcallCounterStack.size() > 120) {
drawcallCounterStack.removeFirst();
}
int screenHeight = Gdx.graphics.getHeight();
int screenWidth = Gdx.graphics.getWidth();
// Render information
spriteBatch.begin();
font.draw(spriteBatch, "Position (XYZ): " + camera.position.x + "|" + camera.position.y + "|" + camera.position.z, 10, screenHeight);
font.draw(spriteBatch, "LookDir (XYZ): " + camera.direction.x + "|" + camera.direction.y + "|" + camera.direction.z, 10, screenHeight - 20);
font.draw(spriteBatch, "FPS: " + Gdx.graphics.getFramesPerSecond(), screenWidth - 100, screenHeight - 20);
font.draw(spriteBatch, "Draw calls: " + GLProfiler.drawCalls, 10, screenHeight - 40);
// TODO Why does this produce the same as Draw calls: ?
font.draw(spriteBatch, "Vertex Count: " + (int) GLProfiler.vertexCount.total, 10, screenHeight - 60);
font.draw(spriteBatch, "Texture Bindings: " + GLProfiler.textureBindings, 10, screenHeight - 80);
// VM Info
int mb = 1024 * 1024;
// Getting the runtime reference from system
Runtime runtime = Runtime.getRuntime();
font.draw(spriteBatch, "Used Memory: " + (runtime.totalMemory() - runtime.freeMemory()) / mb + " MB", 10, screenHeight - 120);
font.draw(spriteBatch, "Free Memory: " + runtime.freeMemory() / mb + " MB", 10, screenHeight - 140);
font.draw(spriteBatch, "Total Memory: " + runtime.totalMemory() / mb + " MB", 10, screenHeight - 160);
font.draw(spriteBatch, "Max Memory: " + runtime.maxMemory() / mb + " MB", 10, screenHeight - 180);
font.draw(spriteBatch, "Java VM: " + System.getProperty("java.vm.name"), 10, screenHeight - 200);
spriteBatch.end();
// Diagrams
if (drawDiagrams) {
// FPS-Diagram
float[] fpsEntries = new float[fpsCounterStack.size()];
for (int i = 0; i < fpsEntries.length; i++) fpsEntries[i] = fpsCounterStack.get(i);
StatisticsHelper.renderLineDiagram("FPS", new Vector2(screenWidth - 350, 10), new Vector2(300, 200), fpsEntries, 0f);
// Drawcall-Diagram
float[] drawcallEntries = new float[drawcallCounterStack.size()];
for (int i = 0; i < drawcallEntries.length; i++) drawcallEntries[i] = drawcallCounterStack.get(i);
StatisticsHelper.renderLineDiagram("Drawcalls", new Vector2(screenWidth - 350, 250), new Vector2(300, 200), drawcallEntries, 0f);
// Render profiling results
String[] profilingNames = new String[] { "Update", "Render" };
Color[] profilingColors = new Color[] { Color.RED, Color.GREEN };
// Get profiling results
float[] profilingValues = new float[profilingNames.length];
for (int i = 0; i < profilingValues.length; i++) {
// Get profiling result
profilingValues[i] = CubicWorld.getClient().profiler.getProfilerResult(profilingNames[i]);
}
// Render profiling legend
int yAxisPosition = 700;
spriteBatch.begin();
for (int i = 0; i < profilingNames.length; i++) {
Vector2 currentPosition = new Vector2(screenWidth - 130, yAxisPosition);
font.setColor(profilingColors[i]);
font.draw(spriteBatch, profilingNames[i] + " " + new DecimalFormat("#.##").format((profilingValues[i] / 1000.0f) / 1000.0f), currentPosition.x, currentPosition.y);
yAxisPosition -= 20;
}
spriteBatch.end();
// Reset font color
font.setColor(Color.WHITE);
StatisticsHelper.renderPiechart("Profilings", new Vector2(screenWidth - 350, 500), 100, profilingValues, profilingColors);
}
// Network diagrams
if (drawNetworkDiagrams) {
// Upstream-Diagram
float[] upstreamEntries = new float[upstreamBytesStack.size()];
for (int i = 0; i < upstreamEntries.length; i++) upstreamEntries[i] = upstreamBytesStack.get(i).floatValue() / 1024f;
StatisticsHelper.renderLineDiagram("Upstream (kB)", new Vector2(screenWidth - 700, 250), new Vector2(300, 200), upstreamEntries, 0f);
// Downstream-Diagram
float[] downstreamEntries = new float[downstreamBytesStack.size()];
for (int i = 0; i < downstreamEntries.length; i++) downstreamEntries[i] = downstreamBytesStack.get(i).floatValue() / 1024f;
StatisticsHelper.renderLineDiagram("Downstream (kB)", new Vector2(screenWidth - 700, 10), new Vector2(300, 200), downstreamEntries, 0f);
}
}Example 12
| Project: libgdx-master File: GlyphLayout.java View source code |
/** @param color The default color to use for the text (the BitmapFont {@link BitmapFont#getColor() color} is not used). If * {@link BitmapFontData#markupEnabled} is true, color markup tags in the specified string may change the color for * portions of the text. * @param halign Horizontal alignment of the text, see {@link Align}. * @param targetWidth The width used for alignment, line wrapping, and truncation. May be zero if those features are not used. * @param truncate If not null and the width of the glyphs exceed targetWidth, the glyphs are truncated and the glyphs for the * specified truncate string are placed at the end. Empty string can be used to truncate without adding glyphs. * Truncate should not be used with text that contains multiple lines. Wrap is ignored if truncate is not null. */ public void setText(BitmapFont font, CharSequence str, int start, int end, Color color, float targetWidth, int halign, boolean wrap, String truncate) { if (truncate != null) // Causes truncate code to run, doesn't actually cause wrapping. wrap = true; else if (targetWidth <= // font.data.spaceWidth) // Avoid one line per character, which is very inefficient. wrap = false; BitmapFontData fontData = font.data; boolean markupEnabled = fontData.markupEnabled; Pool<GlyphRun> glyphRunPool = Pools.get(GlyphRun.class); Array<GlyphRun> runs = this.runs; glyphRunPool.freeAll(runs); runs.clear(); float x = 0, y = 0, width = 0; int lines = 0, blankLines = 0; Array<Color> colorStack = this.colorStack; Color nextColor = color; colorStack.add(color); Pool<Color> colorPool = Pools.get(Color.class); int runStart = start; outer: while (true) { // Each run is delimited by newline or left square bracket. int runEnd = -1; boolean newline = false, colorRun = false; if (start == end) { // End of string with no run to process, we're done. if (runStart == end) break; // End of string, process last run. runEnd = end; } else { switch(str.charAt(start++)) { case '\n': // End of line. runEnd = start - 1; newline = true; break; case '[': // Possible color tag. if (markupEnabled) { int length = parseColorMarkup(str, start, end, colorPool); if (length >= 0) { runEnd = start - 1; start += length + 1; nextColor = colorStack.peek(); colorRun = true; } else if (length == -2) { // Skip first of "[[" escape sequence. start++; continue outer; } } break; } } if (runEnd != -1) { if (// Can happen (eg) when a color tag is at text start or a line is "\n". runEnd != runStart) { // Store the run that has ended. GlyphRun run = glyphRunPool.obtain(); run.color.set(color); run.x = x; run.y = y; fontData.getGlyphs(run, str, runStart, runEnd, colorRun); if (run.glyphs.size == 0) glyphRunPool.free(run); else { runs.add(run); // Compute the run width, wrap if necessary, and position the run. float[] xAdvances = run.xAdvances.items; for (int i = 0, n = run.xAdvances.size; i < n; i++) { float xAdvance = xAdvances[i]; x += xAdvance; // Don't wrap if the glyph would fit with just its width (no xadvance or kerning). if (wrap && x > targetWidth && i > 1 && x - xAdvance + (run.glyphs.get(i - 1).xoffset + run.glyphs.get(i - 1).width) * fontData.scaleX - 0.0001f > targetWidth) { if (truncate != null) { truncate(fontData, run, targetWidth, truncate, i, glyphRunPool); x = run.x + run.width; break outer; } int wrapIndex = fontData.getWrapIndex(run.glyphs, i); if (// Require at least one glyph per line. (run.x == 0 && wrapIndex == 0) || // Wrap at least the glyph that didn't fit. wrapIndex >= run.glyphs.size) { wrapIndex = i - 1; } GlyphRun next; if (wrapIndex == 0) // No wrap index, move entire run to next line. next = run; else { next = wrap(fontData, run, glyphRunPool, wrapIndex, i); runs.add(next); } // Start the loop over with the new run on the next line. width = Math.max(width, run.x + run.width); x = 0; y += fontData.down; lines++; next.x = 0; next.y = y; i = -1; n = next.xAdvances.size; xAdvances = next.xAdvances.items; run = next; } else run.width += xAdvance; } } } if (newline) { // Next run will be on the next line. width = Math.max(width, x); x = 0; float down = fontData.down; if (// Blank line. runEnd == // Blank line. runStart) { down *= fontData.blankLineScale; blankLines++; } else lines++; y += down; } runStart = start; color = nextColor; } } width = Math.max(width, x); for (int i = 1, n = colorStack.size; i < n; i++) colorPool.free(colorStack.get(i)); colorStack.clear(); // Align runs to center or right of targetWidth. if (// Not left aligned, so must be center or right aligned. (halign & Align.left) == 0) { boolean center = (halign & Align.center) != 0; float lineWidth = 0, lineY = Integer.MIN_VALUE; int lineStart = 0, n = runs.size; for (int i = 0; i < n; i++) { GlyphRun run = runs.get(i); if (run.y != lineY) { lineY = run.y; float shift = targetWidth - lineWidth; if (center) shift /= 2; while (lineStart < i) runs.get(lineStart++).x += shift; lineWidth = 0; } lineWidth += run.width; } float shift = targetWidth - lineWidth; if (center) shift /= 2; while (lineStart < n) runs.get(lineStart++).x += shift; } this.width = width; this.height = fontData.capHeight + lines * fontData.lineHeight + blankLines * fontData.lineHeight * fontData.blankLineScale; }
Example 13
| Project: libgdx-cocostudio-master File: SelectBox.java View source code |
public void setItems(Object[] objects) {
if (objects == null)
throw new IllegalArgumentException("items cannot be null.");
if (!(objects instanceof String[])) {
String[] strings = new String[objects.length];
for (int i = 0, n = objects.length; i < n; i++) strings[i] = String.valueOf(objects[i]);
objects = strings;
}
this.items = (String[]) objects;
selectedIndex = 0;
Drawable bg = style.background;
BitmapFont font = style.font;
prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2, bg.getMinHeight());
float max = 0;
for (int i = 0; i < items.length; i++) max = Math.max(font.getBounds(items[i]).width, max);
prefWidth = bg.getLeftWidth() + bg.getRightWidth() + max;
prefWidth = Math.max(prefWidth, max + style.listBackground.getLeftWidth() + style.listBackground.getRightWidth() + 2 * style.itemSpacing);
invalidateHierarchy();
}Example 14
| Project: catchr-master File: ParticalTest.java View source code |
@Override
public void create() {
camera = new OrthographicCamera();
batch = new SpriteBatch();
effect = new ParticleEffect();
font = new BitmapFont();
camera.setToOrtho(false, 600, 600);
effect.load(Gdx.files.internal("data/squrt.p"), Gdx.files.internal("data"));
effect.setPosition(100f, 100f);
effect.start();
}Example 15
| Project: Dodgy-Dot-master File: DodgyDot.java View source code |
@Override
public void create() {
pref = Gdx.app.getPreferences("DATA");
highScore = pref.getInteger("Score", -1);
if (highScore == -1) {
highScore = 0;
pref.putInteger("Score", 0);
pref.flush();
}
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("ChicagoFLF.fnt"));
//font.setScale(5f);
labelStyle = new Label.LabelStyle(font, new Color(124 / 255.0f, 199 / 255.0f, 72 / 255.0f, 1));
highScoreWordsLabel = new Label("Score:\n\nHigh Score:", labelStyle);
highScoreWordsLabel.setFontScale(0.7f);
highScoreWordsLabel.setHeight((float) highScoreWordsLabel.getHeight() * 0.7f);
highScoreWordsLabel.setPosition(0, VIRTUAL_HEIGHT - highScoreWordsLabel.getHeight());
highScoreWordsLabel.setAlignment(Align.left);
//debugRenderer = new Box2DDebugRenderer();
Assets.load();
this.setScreen(new GameScreen(this));
}Example 16
| Project: DreamsLibGdx-master File: ResourcesManager.java View source code |
private void loadAssetsGame() {
Gdx.app.log(Constants.LOG, "Load ResourcesManager Game");
this.load(DEFAULT_FONT, BitmapFont.class);
this.load(DEBUG_FONT, BitmapFont.class);
this.load(HEADER_FONT, BitmapFont.class);
this.load(DEBUG_BACKGROUND, Texture.class);
this.load(MENU_BACKGROUND, Texture.class);
this.load(STATS_BACKGROUND, Texture.class);
this.load(SPRITE_ATLAS, TextureAtlas.class);
this.load(VARIOS_ATLAS, TextureAtlas.class);
this.load(OBJECTS_ATLAS, TextureAtlas.class);
this.load(GUI_ATLAS, TextureAtlas.class);
this.load(GUI_PACK_ATLAS, TextureAtlas.class);
this.load(UISKIN_ATLAS, TextureAtlas.class);
this.load(PARTICLE_EFFECT, ParticleEffect.class);
this.load(PARTICLE_EFFECT_CONTACT, ParticleEffect.class);
this.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
this.load(MUSIC_MENU, Music.class);
}Example 17
| Project: Droha-Beta-master File: Assets.java View source code |
public static void cargar() {
if (Gdx.graphics.getWidth() > Gdx.graphics.getHeight()) {
escala = Gdx.graphics.getHeight() / 6;
} else {
escala = Gdx.graphics.getWidth() / 6;
}
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/empaquetado.atlas"));
fuenteBoton = new BitmapFont(Gdx.files.internal("data/forte.fnt"), atlas.findRegion("menu/forte"), false);
if (Gdx.graphics.getWidth() < 400) {
fuenteBoton.setScale(0.7f);
} else if (Gdx.graphics.getWidth() < 900) {
fuenteBoton.setScale(0.9f);
} else if (Gdx.graphics.getWidth() < 1200) {
fuenteBoton.setScale(1.3f);
} else if (Gdx.graphics.getWidth() < 1600) {
fuenteBoton.setScale(1.5f);
} else {
fuenteBoton.setScale(2f);
}
skin = new Skin();
skin.add("boton", new TextureRegion(atlas.findRegion("menu/boton1")));
skin.add("fondoMenu", new TextureRegion(atlas.findRegion("escenario/fondoMenu")));
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("boton", Color.WHITE);
textButtonStyle.down = skin.newDrawable("boton", Color.GREEN);
textButtonStyle.over = skin.newDrawable("boton", new Color(1, 0.5f, 1, 0.95f));
textButtonStyle.font = fuenteBoton;
skin.add("default", textButtonStyle);
LabelStyle labelStyle = new LabelStyle();
labelStyle.font = fuenteBoton;
skin.add("default", labelStyle);
}Example 18
| Project: flixel-gdx-master File: FreeTypeFontLoader.java View source code |
@Override public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) { String[] split = fileName.split(":"); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(resolve(split[1])); FreeTypeFontParameter param = new FreeTypeFontParameter(); param.size = Integer.parseInt(split[0]); param.flip = (parameter != null) ? parameter.flip : true; param.characters = freeTypeFontChars; BitmapFont font = generator.generateFont(param); generator.dispose(); return font; }
Example 19
| Project: gdx-combat-master File: Assets.java View source code |
public static void load() {
textures = new TextureAtlas(Gdx.files.internal("gfx/textures.pack"));
timerFont = new BitmapFont(Gdx.files.internal("timer.fnt"), textures.findRegion("timer"));
fight = Gdx.audio.newSound(Gdx.files.internal("sounds/fight.mp3"));
for (int i = 0; i < 7; i++) {
hitSounds.add(Gdx.audio.newSound(Gdx.files.internal("sounds/hit" + i + ".mp3")));
}
}Example 20
| Project: gdx-lml-master File: SkinService.java View source code |
private static void loadFonts(final String atlasPath, final String[] fontPaths, final AssetService assetService) {
if (fontPaths.length != 0) {
final BitmapFontParameter loadingParameters = new BitmapFontParameter();
loadingParameters.atlasName = atlasPath;
for (final String fontPath : fontPaths) {
assetService.finishLoading(fontPath, BitmapFont.class, loadingParameters);
}
}
}Example 21
| Project: gdx-smart-font-master File: SmartFontGenerator.java View source code |
/** Will load font from file. If that fails, font will be generated and saved to file. * @param fontFile the actual font (.otf, .ttf) * @param fontName the name of the font, i.e. "arial-small", "arial-large", "monospace-10" * This will be used for creating the font file names * @param fontSize size of font when screen width equals referenceScreenWidth */ public BitmapFont createFont(FileHandle fontFile, String fontName, int fontSize) { BitmapFont font = null; // if fonts are already generated, just load from file Preferences fontPrefs = Gdx.app.getPreferences("org.jrenner.smartfont"); int displayWidth = fontPrefs.getInteger("display-width", 0); int displayHeight = fontPrefs.getInteger("display-height", 0); boolean loaded = false; if (displayWidth != Gdx.graphics.getWidth() || displayHeight != Gdx.graphics.getHeight()) { Gdx.app.debug(TAG, "Screen size change detected, regenerating fonts"); } else { try { // try to load from file Gdx.app.debug(TAG, "Loading generated font from file cache"); font = new BitmapFont(getFontFile(fontName + ".fnt", fontSize)); loaded = true; } catch (GdxRuntimeException e) { Gdx.app.error(TAG, e.getMessage()); Gdx.app.debug(TAG, "Couldn't load pre-generated fonts. Will generate fonts."); } } if (!loaded || forceGeneration) { forceGeneration = false; float width = Gdx.graphics.getWidth(); // use 1920x1280 as baseline, arbitrary float ratio = width / referenceScreenWidth; // for 28 sized fonts at baseline width above float baseSize = 28f; // store screen width for detecting screen size change // on later startups, which will require font regeneration fontPrefs.putInteger("display-width", Gdx.graphics.getWidth()); fontPrefs.putInteger("display-height", Gdx.graphics.getHeight()); fontPrefs.flush(); font = generateFontWriteFiles(fontName, fontFile, fontSize, pageSize, pageSize); } return font; }
Example 22
| Project: GoingUnder-master File: TutorialScene.java View source code |
private void drawDefault() {
GameHelper.clearScreen();
// draw background and player and arrow and button
gameData.setProjectionMatrix(spriteBatch.getProjectionMatrix());
spriteBatch.begin();
background.draw(spriteBatch);
arrow.draw(spriteBatch);
button.draw(spriteBatch, buttonAlpha);
player.draw(spriteBatch);
spriteBatch.end();
// draw additional text. Is this necessary?
spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, 1080, 1920);
spriteBatch.begin();
BitmapFont font = gameManager.getBitmapFont();
font.setScale(1.0f);
font.setColor(Color.BLACK);
/*
String txt = "Tap to";
font.draw(spriteBatch, txt, (screenWidth - font.getBounds(txt).width) / 2.0f + 5.0f, 1160);
txt = isLeft() ? "push imp right" : "push imp left";
font.draw(spriteBatch, txt, (screenWidth - font.getBounds(txt).width) / 2.0f + 5.0f, 1060);
*/
String txt = "Tap!";
float base = isLeft() ? 0 : 540;
font.draw(spriteBatch, txt, (540 - font.getBounds(txt).width) / 2.0f + 5.0f + base, 1100);
font.setColor(Color.ORANGE);
font.draw(spriteBatch, txt, (540 - font.getBounds(txt).width) / 2.0f + base, 1110);
spriteBatch.end();
}Example 23
| Project: libgdx-cookbook-master File: SpineSample.java View source code |
@Override
public void create() {
camera = new OrthographicCamera();
viewport = new FitViewport(SCENE_WIDTH, SCENE_HEIGHT, camera);
// Center camera
viewport.getCamera().position.set(viewport.getCamera().position.x + SCENE_WIDTH * 0.5f, viewport.getCamera().position.y + SCENE_HEIGHT * 0.5f, 0);
viewport.getCamera().update();
viewport.update((int) SCENE_WIDTH, (int) SCENE_HEIGHT);
font = new BitmapFont(Gdx.files.internal("data/font.fnt"));
stage = new Stage(new FitViewport(1280, 720));
Gdx.input.setInputProcessor(stage);
batch = new SpriteBatch();
renderer = new SkeletonRenderer();
debugRenderer = new SkeletonRendererDebug();
debugRenderer.setBones(true);
debugRenderer.setRegionAttachments(true);
debugRenderer.setBoundingBoxes(true);
debugRenderer.setMeshHull(true);
debugRenderer.setMeshTriangles(true);
loadSkeleton(Gdx.files.internal("data/spine/hero.json"), false);
// Buttons
TextButton.TextButtonStyle tbs = new TextButton.TextButtonStyle();
tbs.font = font;
tbs.up = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("data/scene2d/myactor.png"))));
runBtn = new TextButton("Run", tbs);
runBtn.setPosition(50, 600);
runBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
state.clearTracks();
skeleton.setToSetupPose();
state.setAnimation(0, "run", true);
}
;
});
punchBtn = new TextButton("Punch", tbs);
punchBtn.setPosition(50, 500);
punchBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
state.clearTracks();
skeleton.setToSetupPose();
state.setAnimation(0, "punch", false);
}
;
});
run2idleBtn = new TextButton("Run2Idle", tbs);
run2idleBtn.setPosition(50, 400);
run2idleBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
state.clearTracks();
skeleton.setToSetupPose();
state.setAnimation(0, "run", true);
state.setAnimation(0, "idle", true);
}
;
});
stage.addActor(runBtn);
stage.addActor(punchBtn);
stage.addActor(run2idleBtn);
}Example 24
| Project: mint4j-master File: LoginGame.java View source code |
@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
//
TextButtonStyle style = new TextButtonStyle();
style.font = new BitmapFont();
TextButton button1 = new TextButton("Button 1", style);
table.add(button1);
}Example 25
| Project: Missing_Words-master File: InputButtonListener.java View source code |
@Override
public void clicked(InputEvent event, float x, float y) {
BitmapFont font = new BitmapFont(Gdx.files.internal("fonts/myfont.fnt"), Gdx.files.internal("fonts/myfont.png"), false);
LabelStyle lStyle = new LabelStyle(font, Color.BLACK);
/* Obtenemos todas las fichas que estén en el submitBox para su comprobación */
SnapshotArray<Actor> array = missingWords.getGameScreen().getSubmitBox().getChildren();
/*
* Creamos un objeto de tipo StringBuilder que nos sirve para construir un String con
* la palabra que forman las fichas.
*/
StringBuilder word = new StringBuilder();
int score = 0;
for (int i = 0; i < array.size; ++i) {
Tile t = (Tile) array.get(i);
if (t.getLetter().equals("ae"))
if (i == 0)
word.append("ä".toUpperCase());
else
word.append("ä");
else if (t.getLetter().equals("oe"))
if (i == 0)
word.append("ö".toUpperCase());
else
word.append("ö");
else if (t.getLetter().equals("ue"))
if (i == 0)
word.append("ü".toUpperCase());
else
word.append("ü");
else if (i == 0)
word.append(t.getLetter().toUpperCase());
else
word.append(t.getLetter());
score += t.getPoints();
}
/* Si la palabra está en el vocbulario */
if (missingWords.getVocabulary().getVocabulary().containsKey(word.toString())) {
/* Reproducimos el efecto de sonido si está activo */
missingWords.getSoundFX().getPositiveSound().play(missingWords.getSoundFX().getVolume());
/* Calculamos el número de tiradas en base a los puntos del jugador */
missingWords.getGameScreen().getHuman().calculateRolls(score);
/* Añadimos la palabra a la lista de palabras jugadas */
missingWords.getGameScreen().getHuman().addPlayedWord(word.toString());
/* Creamos una etiqueta y mostramos el mensaje */
Label nice = new Label("Nice!", lStyle);
if (missingWords.selectedLanguage == Language.german)
nice.setText("Gut!");
nice.setPosition(0, 0);
nice.addAction(Actions.fadeOut(1));
missingWords.getGameScreen().getStage().addActor(nice);
// TotalWords + 1
missingWords.getGameScreen().increaseTotalWords();
/* Añadimos los datos a las estadísticas */
missingWords.getStatsData().increaseMaxWords();
missingWords.getStatsData().increaseCorrectWords();
/* Añadimos la palabra a las estadísticas de su categoría */
missingWords.getCategoryData().addWord(word.toString());
/* Comprobamos si hemos formado una palabra más larga y la añadimos si es así */
if (missingWords.getStatsData().getLargestWord().length() < word.length())
missingWords.getStatsData().setLargestWord(word.toString());
/* Comprobamos si hemos formado una palabra con más puntos y la añadimos si es así */
missingWords.getStatsData().setBestWord(word.toString(), score);
/* El jugador confirma la palabra y juega al minijuego */
missingWords.getGameScreen().getHuman().playTurn();
} else // Si no está, se muestra con una etiqueta
{
/* Reproducimos el efecto de sonido si está activo */
missingWords.getSoundFX().getNegativeSound().play(missingWords.getSoundFX().getVolume());
Label notfound = new Label("Not found!", lStyle);
notfound.setPosition(630, 0);
if (missingWords.selectedLanguage == Language.german) {
notfound.setText("Nicht gefunden");
notfound.setPosition(550, 0);
}
notfound.addAction(Actions.fadeOut(1));
missingWords.getGameScreen().getStage().addActor(notfound);
}
}Example 26
| Project: MountainRangePvP-master File: TextRenderer.java View source code |
public void setSize(int size) {
if (fonts[size] != null) {
current = fonts[size];
} else {
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = size;
BitmapFont font = generator.generateFont(parameter);
font.setColor(0, 0, 0, 1);
fonts[size] = font;
current = font;
}
}Example 27
| Project: naturally-selected-2d-master File: UIStopwatchRenderSytem.java View source code |
@Override
protected void processSystem() {
bounce += world.delta;
batch.setProjectionMatrix(cameraSystem.guiCamera.combined);
batch.begin();
batch.setColor(1f, 1f, 1f, 1f);
assetSystem.fontLarge.setColor(1f, 1f, 1f, 1f);
String cost = formatAge();
BitmapFont.TextBounds bounds = assetSystem.fontLarge.getBounds(cost);
if (gameOver) {
if (G.settings.personalHighscore < (int) age) {
improvement = (int) age - G.settings.personalHighscore;
G.settings.personalHighscore = (int) age;
G.settings.save();
}
// disable these systems
stageRenderSystem.setEnabled(false);
playerControlSystem.setEnabled(false);
assetSystem.fontLarge.setScale(Interpolation.elastic.apply(3, (improvement > 0 ? 4 : 3), Math.abs((bounce % 2) - 1)));
BitmapFont.TextBounds bounds2 = assetSystem.fontLarge.getBounds(cost);
assetSystem.fontLarge.draw(batch, cost, Gdx.graphics.getWidth() / 4 - bounds2.width / 2, Gdx.graphics.getHeight() / 4 + bounds2.height / 2 + 5);
assetSystem.fontLarge.setScale(3);
String message = improvement > 0 ? "Game over! Personal highscore! You survived for:" : "Game Over! You survived for:";
bounds = assetSystem.font.getBounds(message);
assetSystem.font.draw(batch, message, Gdx.graphics.getWidth() / 4 - bounds.width / 2, Gdx.graphics.getHeight() / 4 + 40);
retryCooldown -= world.delta;
if (retryCooldown <= 0) {
message = "Press space to try again";
bounds = assetSystem.font.getBounds(message);
assetSystem.font.draw(batch, message, Gdx.graphics.getWidth() / 4 - bounds.width / 2, Gdx.graphics.getHeight() / 4 - 30);
if (Gdx.input.isKeyPressed(Input.Keys.SPACE)) {
G.game.restart();
return;
}
}
} else {
age += world.delta;
assetSystem.fontLarge.draw(batch, cost, Gdx.graphics.getWidth() / 2 - bounds.width - 10, Gdx.graphics.getHeight() / 2 + 10);
String message = "Stage " + (directorSystem.activeStage + 1);
}
batch.end();
}Example 28
| Project: shadow-engine-master File: TextInputLevel.java View source code |
@Override
public void renderImpl() {
showtitle = false;
super.renderImpl();
Rectangle vp = Shadow.cam.camrec;
BitmapFont.TextBounds bounds = font.getBounds(string[0] + indicator);
String txt = string[0] + indicator;
float x = vp.x + vp.width / 2f - bounds.width / 2f;
float y = vp.y + vp.height / 2f - bounds.height / 2f;
font.setColor(0f, 0f, 0f, 0.5f);
font.draw(Shadow.spriteBatch, txt, x + 0.0825f, y + 0.0825f);
font.setColor(1f, 1f, 1f, 1f);
font.draw(Shadow.spriteBatch, txt, x, y);
}Example 29
| Project: Vloxlands-master File: LoadingLayer.java View source code |
@Override
public void show() {
modal = true;
Vloxlands.assets.load("img/logo/logo256.png", Texture.class);
Vloxlands.assets.load("img/logo/logo256-blur.png", Texture.class);
Vloxlands.assets.finishLoading();
stage = new Stage(new ScreenViewport());
font = new BitmapFont();
logo = new Image(Vloxlands.assets.get("img/logo/logo256.png", Texture.class));
blur = Vloxlands.assets.get("img/logo/logo256-blur.png", Texture.class);
worldGenerator = new WorldGenerator();
stage.addActor(logo);
InternalAssetManager.scheduleDirectory(Vloxlands.assets, "img", Texture.class, true);
InternalAssetManager.scheduleDirectory(Vloxlands.assets, "models", Model.class, new FileNameExtensionFilter("g3db", "vxi"), true);
}Example 30
| Project: 3DRoguelike-master File: LevelGraphics.java View source code |
public void createMap(Tile[][] levelArray) {
BitmapFont font = new BitmapFont();
SpriteBatch sB = new SpriteBatch();
FrameBuffer fB = new FrameBuffer(Format.RGBA4444, width * STEP, height * STEP, false);
fB.begin();
sB.begin();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
char c = levelArray[x][y].character;
if (c == ' ')
continue;
font.setColor(colours.get(c));
font.draw(sB, "" + c, x * STEP, y * STEP);
}
}
sB.end();
fB.end();
map = fB.getColorBufferTexture();
}Example 31
| Project: arktrail-master File: BarRenderSystem.java View source code |
protected void process(final Entity entity) {
final Bar bar = mBar.get(entity);
final Pos pos = pm.get(entity);
final BitmapFont font = fontManager.font;
if (mColor.has(entity)) {
final Color color = mColor.get(entity);
font.setColor(color.r, color.g, color.b, color.a);
batch.setColor(color.r, color.g, color.b, color.a);
} else {
font.setColor(1f, 1f, 1f, 1f);
batch.setColor(1f, 1f, 1f, 1f);
}
font.draw(batch, bar.text, roundToPixels(pos.x), roundToPixels(pos.y));
BitmapFont.TextBounds bounds = font.getBounds(bar.text);
final com.badlogic.gdx.graphics.g2d.Animation gdxanim = abstractAssetSystem.get(bar.animationId);
if (gdxanim == null)
return;
final com.badlogic.gdx.graphics.g2d.Animation gdxanim2 = abstractAssetSystem.get(bar.animationIdEmpty);
if (gdxanim2 == null)
return;
final TextureRegion frame = gdxanim.getKeyFrame(0, false);
final TextureRegion frame2 = gdxanim2.getKeyFrame(0, false);
// make sure one bubble is always shown.
int emptyCount = (bar.value == 0 && bar.valueEmpty == 0) ? 1 : bar.valueEmpty;
int barWidth = frame.getRegionWidth() + 1;
if (bar.value + bar.valueEmpty >= 10)
barWidth -= 1;
if (bar.value + bar.valueEmpty >= 20)
barWidth -= 1;
if (bar.value + bar.valueEmpty >= 30)
barWidth -= 1;
if (bar.value + bar.valueEmpty >= 40)
barWidth -= 1;
for (int i = 0; i < bar.value; i++) {
batch.draw(frame, roundToPixels(pos.x + bounds.width + i * barWidth), roundToPixels(pos.y - bounds.height), frame.getRegionWidth(), frame.getRegionHeight());
}
for (int i = 0; i < emptyCount; i++) {
batch.draw(frame2, roundToPixels(pos.x + bounds.width + (i + bar.value) * barWidth), roundToPixels(pos.y - bounds.height), frame.getRegionWidth(), frame.getRegionHeight());
}
}Example 32
| Project: artemis-odb-contrib-master File: LabelRenderSystem.java View source code |
protected void process(final int e) {
final Label label = mLabel.get(e);
final Pos pos = mPos.get(e);
if (label.text != null) {
final BitmapFont font = mBitmapFontAsset.get(e).bitmapFont;
batch.setColor(mTint.getSafe(e, Tint.WHITE).color);
switch(label.align) {
case LEFT:
font.draw(batch, label.text, pos.xy.x, pos.xy.y);
break;
case RIGHT:
glyphLayout.setText(font, label.text);
font.draw(batch, label.text, pos.xy.x - glyphLayout.width, pos.xy.y);
break;
}
}
}Example 33
| Project: cs185-master File: ScreenTest.java View source code |
/**----------------------------------------------------------------------------------
* Sets up the stage, and sets the skins for the buttons. Then sets the buttons.
* This is all very messy. Only for developers type of thing. Why are you reading
* this comment. It is completely useless. Well, not completely. I guess it does have
* some use. Well, in any case, this method is a complete mess.
* ----------------------------------------------------------------------------------
*/
public void create() {
batch = new SpriteBatch();
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin();
// Generate a 1x1 white texture and store it in the skin named "white".
Pixmap pixmap = new Pixmap(100, 100, Format.RGBA8888);
pixmap.setColor(Color.GREEN);
pixmap.fill();
skin.add("white", new Texture(pixmap));
BitmapFont bfont = new BitmapFont();
bfont.scale(1);
skin.add("default", bfont);
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
// 300
final int dX = 200;
// 120
final int dY = 100;
// 200
final int xOff = 50;
// 200
final int yOff = 100;
final TextButton textButton = new TextButton("L1 R1", textButtonStyle);
textButton.setPosition(xOff + 0 * dX, yOff + 1 * dY);
stage.addActor(textButton);
textButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,Level1Run1,changeMusic,song1");
}
});
final TextButton textButton2 = new TextButton("L1 M1", textButtonStyle);
textButton2.setPosition(xOff + 1 * dX, yOff + 1 * dY);
stage.addActor(textButton2);
textButton2.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,Level1Maze1");
}
});
final TextButton textButton4 = new TextButton("L1 M2", textButtonStyle);
textButton4.setPosition(xOff + 2 * dX, yOff + 1 * dY);
stage.addActor(textButton4);
textButton4.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,Level1Maze2,changeMyAnim,Bowling");
}
});
final TextButton textButton3 = new TextButton("L2 M1", textButtonStyle);
textButton3.setPosition(xOff + 0 * dX, yOff + 0 * dY);
stage.addActor(textButton3);
textButton3.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,Level2Maze1");
}
});
final TextButton textButton5 = new TextButton("L2 R1", textButtonStyle);
textButton5.setPosition(xOff + 1 * dX, yOff + 0 * dY);
stage.addActor(textButton5);
textButton5.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,Level2Runner1,changeMyAnim,Tennis");
}
});
final TextButton textButton6 = new TextButton("volcano", textButtonStyle);
textButton6.setPosition(xOff + 2 * dX, yOff + 0 * dY);
stage.addActor(textButton6);
textButton6.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,volcano");
}
});
final TextButton textButton7 = new TextButton("endDialog", textButtonStyle);
textButton7.setPosition(xOff + 0 * dX, yOff + 2 * dY);
stage.addActor(textButton7);
textButton7.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
g.i().t.action("NewLevel,dialogOutro");
}
});
}Example 34
| Project: gdxGame-master File: Gdxgame.java View source code |
public void create() {
Tween.setCombinedAttributesLimit(4);
Tween.registerAccessor(Color.class, new ColorAccessor());
Tween.registerAccessor(PointLight.class, new LightAccessor());
atlas = new TextureAtlas(Gdx.files.internal("game.atlas"));
pling = Gdx.audio.newSound(Gdx.files.internal("sounds/Pling.mp3"));
ground = atlas.findRegion("ground");
rocket = atlas.findRegion("player_liten");
pickup = atlas.findRegion("light_liten");
pickupBad = atlas.findRegion("light_liten");
font = new BitmapFont(Gdx.files.internal("fonts/SIL.fnt"));
font2 = new BitmapFont(Gdx.files.internal("fonts/font2.fnt"));
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();
bot = -((h / w) / 2);
top = ((h / w) / 2);
left = -(1.0f) / 2;
right = (1.0f) / 2;
camera = new OrthographicCamera(w / h, 1);
mygame = this;
mainmenu = new MainMenu();
bouncingBalls = new BouncingBalls();
randomCurves = new RandomCurves();
setScreen(mainmenu);
}Example 35
| Project: Klooni1010-master File: ShareChallenge.java View source code |
// Saves the "Challenge me" shareable image to getShareImageFilePath()
public boolean saveChallengeImage(final int score, final boolean timeMode) {
final File saveAt = getShareImageFilePath();
if (!saveAt.getParentFile().isDirectory())
if (!saveAt.mkdirs())
return false;
final FileHandle output = new FileHandle(saveAt);
final Texture shareBase = new Texture(Gdx.files.internal("share.png"));
final int width = shareBase.getWidth();
final int height = shareBase.getHeight();
final FrameBuffer frameBuffer = new FrameBuffer(Pixmap.Format.RGB888, width, height, false);
frameBuffer.begin();
// Render the base share texture
final SpriteBatch batch = new SpriteBatch();
final Matrix4 matrix = new Matrix4();
matrix.setToOrtho2D(0, 0, width, height);
batch.setProjectionMatrix(matrix);
Gdx.gl.glClearColor(Color.GOLD.r, Color.GOLD.g, Color.GOLD.b, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(shareBase, 0, 0);
// Render the achieved score
final Label.LabelStyle style = new Label.LabelStyle();
style.font = new BitmapFont(Gdx.files.internal("font/x1.0/geosans-light64.fnt"));
Label label = new Label("just scored " + score + " on", style);
label.setColor(Color.BLACK);
label.setPosition(40, 500);
label.draw(batch, 1);
label.setText("try to beat me if you can");
label.setPosition(40, 40);
label.draw(batch, 1);
if (timeMode) {
Texture timeModeTexture = new Texture("ui/x1.5/stopwatch.png");
batch.setColor(Color.BLACK);
batch.draw(timeModeTexture, 200, 340);
}
batch.end();
// Get the framebuffer pixels and write them to a local file
final byte[] pixels = ScreenUtils.getFrameBufferPixels(0, 0, width, height, true);
final Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
BufferUtils.copy(pixels, 0, pixmap.getPixels(), pixels.length);
PixmapIO.writePNG(output, pixmap);
// Dispose everything
pixmap.dispose();
shareBase.dispose();
batch.dispose();
frameBuffer.end();
return true;
}Example 36
| Project: OverdriveGDX-master File: OverdriveGame.java View source code |
@Override
public void create() {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
log = new Logger(OverdriveGame.class.getCanonicalName(), Logger.DEBUG);
log.info(String.format("%s v%s", APP_NAME, APP_VERSION));
log.info(String.format("%s %s", System.getProperty("os.name"), System.getProperty("os.version")));
log.info(String.format("%s, %s, %s", System.getProperty("java.vm.name"), System.getProperty("java.version"), System.getProperty("os.arch")));
appDir = new File(".");
log.info("CWD: " + appDir.getAbsolutePath());
String envAppPath = System.getenv(ENV_APP_PATH);
if (envAppPath != null && envAppPath.length() > 0) {
File envAppDir = new File(envAppPath);
if (envAppDir.exists()) {
log.info(String.format("Environment var (%s) changed app path: %s", ENV_APP_PATH, envAppPath));
appDir = envAppDir;
} else {
log.error(String.format("Environment var (%s) set a non-existent app path: %s", ENV_APP_PATH, envAppPath));
}
}
resourcesDir = new File(appDir, "resources");
java.nio.IntBuffer buf = com.badlogic.gdx.utils.BufferUtils.newIntBuffer(16);
Gdx.gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, buf);
int maxTextureSize = buf.get();
log.debug("Device Estimated Max Texture Size: " + maxTextureSize);
log.debug("Device GL11: " + Gdx.graphics.isGL11Available());
log.debug("Device GL20: " + Gdx.graphics.isGL20Available());
fileHandleResolver = new URIFileHandleResolver();
fileHandleResolver.setResolver("internal:", new InternalFileHandleResolver(), true);
fileHandleResolver.setResolver("external:", new ExternalFileHandleResolver(), true);
fileHandleResolver.addDefaultResolver(new RelativeFileHandleResolver(resourcesDir));
fileHandleResolver.addDefaultResolver(new RelativeFileHandleResolver(appDir));
fileHandleResolver.addDefaultResolver(new InternalFileHandleResolver());
refManager = new OVDReferenceManager();
netManager = new OVDNetManager();
assetManager = new AssetManager(fileHandleResolver);
assetManager.setLoader(BitmapFont.class, new FreeTypeFontLoader(fileHandleResolver));
OverdriveContext context = new OverdriveContext();
context.init(this, null, -1);
screenManager = new OVDScreenManager(context);
screenManager.showScreen(screenManager.getInitScreenKey());
networkTest = new com.ftloverdrive.net.NetworkTest();
//networkTest.init();
}Example 37
| Project: spacefish-master File: LevelScreen.java View source code |
private void drawScores(final SpriteBatch batch) {
final BitmapFont font = GameResources.getInstance().getFont();
batch.enableBlending();
font.setColor(1.0f, 1.0f, 1.0f, 1.0f);
final Fish fish = mController.getGame().getFish();
final String points = String.valueOf(fish.getPoints());
final BitmapFont.TextBounds bounds = font.getBounds(points);
final float x = Dimensions.VIRTUAL_SCREEN_WIDTH - Dimensions.ICON_PADDING - bounds.width;
final float y = Dimensions.VIRTUAL_SCREEN_HEIGHT - bounds.height;
font.draw(batch, points, x, y);
final String speed = "x" + fish.getSpeed();
final BitmapFont.TextBounds bounds1 = font.getBounds(speed);
font.draw(batch, speed, x - bounds1.width - Dimensions.ICON_PADDING, y);
}Example 38
| Project: Zombicalypse-master File: TGame.java View source code |
@Override
public void create() {
if (DEBUG) {
Gdx.app.log(TAG, "game.create()");
}
game = this;
prefs = Gdx.app.getPreferences("zombicalypse.ini");
prefs.getBoolean("effects", true);
prefs.getBoolean("music", true);
music = Gdx.audio.newMusic(Gdx.files.internal("data/snd/music-01.ogg"));
music.setLooping(true);
snd_explosion = new Sound[4];
snd_explosion[0] = Gdx.audio.newSound(Gdx.files.internal("data/snd/explosion-01.ogg"));
snd_explosion[1] = Gdx.audio.newSound(Gdx.files.internal("data/snd/explosion-02.ogg"));
snd_explosion[2] = Gdx.audio.newSound(Gdx.files.internal("data/snd/explosion-03.ogg"));
snd_explosion[3] = Gdx.audio.newSound(Gdx.files.internal("data/snd/explosion-04.ogg"));
snd_zombie = new Sound[4];
snd_zombie[0] = Gdx.audio.newSound(Gdx.files.internal("data/snd/zombie-01.ogg"));
snd_zombie[1] = Gdx.audio.newSound(Gdx.files.internal("data/snd/zombie-02.ogg"));
snd_zombie[2] = Gdx.audio.newSound(Gdx.files.internal("data/snd/zombie-03.ogg"));
snd_zombie[3] = Gdx.audio.newSound(Gdx.files.internal("data/snd/zombie-04.ogg"));
atlas = new TextureAtlas("data/img/pack");
ninepatch = new NinePatchDrawable(new NinePatch(atlas.findRegion("menuskin"), 8, 8, 8, 8));
font = new BitmapFont(new BitmapFontData(Gdx.files.internal("data/primo.fnt"), false), atlas.findRegion("primo"), false);
house = new StillModel[3];
house[0] = G3dLoader.loadStillModel(Gdx.files.internal("data/mdl/house1.g3d"));
house[1] = G3dLoader.loadStillModel(Gdx.files.internal("data/mdl/house2.g3d"));
house[2] = G3dLoader.loadStillModel(Gdx.files.internal("data/mdl/house3.g3d"));
labelStyle = new LabelStyle(font, Color.WHITE);
sliderStyle = new SliderStyle();
sliderStyle.background = ninepatch;
sliderStyle.knob = new TextureRegionDrawable(atlas.findRegion("checkboxon"));
textbuttonStyle = new TextButtonStyle();
textbuttonStyle.font = font;
textbuttonStyle.fontColor = Color.WHITE;
textbuttonStyle.downFontColor = Color.RED;
checkboxStyle = new CheckBoxStyle();
checkboxStyle.font = font;
checkboxStyle.checkboxOn = new TextureRegionDrawable(atlas.findRegion("checkboxon"));
checkboxStyle.checkboxOff = new TextureRegionDrawable(atlas.findRegion("checkboxoff"));
checkboxStyle.checked = new TextureRegionDrawable(atlas.findRegion("checkboxon"));
TGame.highscores = new HighScores();
TGame.options = new Options();
TGame.gameover = new GameOver();
TGame.gameloop = new GameLoop();
TGame.mainmenu = new MainMenu();
Gdx.input.setCatchBackKey(true);
Gdx.input.setCatchMenuKey(true);
Gdx.app.log(TAG, "isGL20 available: " + Gdx.graphics.isGL20Available());
// Gdx.input.setCursorCatched(true);
if (Gdx.graphics.isGL20Available()) {
texshader = new ShaderProgram(tex_vertexShader, tex_fragmentShader);
colshader = new ShaderProgram(col_vertexShader, col_fragmentShader);
if (DEBUG) {
Gdx.app.log(TAG, texshader.getLog());
Gdx.app.log(TAG, colshader.getLog());
}
}
TGame.previous_screen = TGame.mainmenu;
this.setScreen(TGame.mainmenu);
}Example 39
| Project: Aurea-Oceanus-master File: Resources.java View source code |
public void reInit() {
initShader();
breath = Gdx.audio.newMusic(Gdx.files.internal("data/breath.ogg"));
fastBreath = Gdx.audio.newMusic(Gdx.files.internal("data/fastBreath.ogg"));
intro = Gdx.audio.newMusic(Gdx.files.internal("data/intro2.ogg"));
pickUp = Gdx.audio.newSound(Gdx.files.internal("data/pickUp.ogg"));
danger = Gdx.audio.newSound(Gdx.files.internal("data/danger.ogg"));
noBreath = Gdx.audio.newSound(Gdx.files.internal("data/noBreath.ogg"));
getBite = Gdx.audio.newSound(Gdx.files.internal("data/getBite.ogg"));
footStep = Gdx.audio.newSound(Gdx.files.internal("data/footSteps.ogg"));
font = new BitmapFont();
}Example 40
| Project: bladecoder-adventure-engine-master File: MenuScreen.java View source code |
@Override
public void show() {
stage = new Stage(new ScreenViewport());
final Skin skin = ui.getSkin();
final World world = World.getInstance();
final MenuScreenStyle style = getStyle();
final BitmapFont f = skin.get(style.textButtonStyle, TextButtonStyle.class).font;
float buttonWidth = f.getCapHeight() * 15f;
// Image background = new Image(style.background);
Drawable bg = style.background;
if (bg == null && style.bgFile != null) {
bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
float scale = (float) bgTexFile.getHeight() / (float) stage.getViewport().getScreenHeight();
int width = (int) (stage.getViewport().getScreenWidth() * scale);
int x0 = (int) ((bgTexFile.getWidth() - width) / 2);
bg = new TextureRegionDrawable(new TextureRegion(bgTexFile, x0, 0, width, bgTexFile.getHeight()));
}
menuButtonTable.clear();
if (bg != null)
menuButtonTable.setBackground(bg);
menuButtonTable.addListener(new InputListener() {
@Override
public boolean keyUp(InputEvent event, int keycode) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
if (world.getCurrentScene() != null)
ui.setCurrentScreen(Screens.SCENE_SCREEN);
return true;
}
});
menuButtonTable.defaults().pad(BUTTON_PADDING).width(buttonWidth);
stage.setKeyboardFocus(menuButtonTable);
if (style.showTitle) {
Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin, style.titleStyle);
title.setAlignment(Align.center);
menuButtonTable.add(title).padBottom(DPIUtils.getMarginSize() * 2);
menuButtonTable.row();
}
if (world.savedGameExists() || world.getCurrentScene() != null) {
TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle);
continueGame.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
if (world.getCurrentScene() == null)
try {
world.load();
} catch (Exception e) {
Gdx.app.exit();
}
ui.setCurrentScreen(Screens.SCENE_SCREEN);
}
});
menuButtonTable.add(continueGame);
menuButtonTable.row();
}
TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle);
newGame.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
if (world.savedGameExists()) {
Dialog d = new Dialog("", skin) {
protected void result(Object object) {
if (((Boolean) object).booleanValue()) {
try {
world.newGame();
ui.setCurrentScreen(Screens.SCENE_SCREEN);
} catch (Exception e) {
EngineLogger.error("IN NEW GAME", e);
Gdx.app.exit();
}
}
}
};
d.pad(DPIUtils.getMarginSize());
d.getButtonTable().padTop(DPIUtils.getMarginSize());
d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize()).padRight(DPIUtils.getMarginSize());
Label l = new Label(I18N.getString("ui.override"), ui.getSkin(), "ui-dialog");
l.setWrap(true);
l.setAlignment(Align.center);
d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f);
d.button(I18N.getString("ui.yes"), true, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
d.button(I18N.getString("ui.no"), false, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
d.key(Keys.ENTER, true).key(Keys.ESCAPE, false);
d.show(stage);
} else {
try {
world.newGame();
ui.setCurrentScreen(Screens.SCENE_SCREEN);
} catch (Exception e) {
EngineLogger.error("IN NEW GAME", e);
Gdx.app.exit();
}
}
}
});
menuButtonTable.add(newGame);
menuButtonTable.row();
TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle);
loadGame.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN);
}
});
menuButtonTable.add(loadGame);
menuButtonTable.row();
TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle);
quit.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gdx.app.exit();
}
});
menuButtonTable.add(quit);
menuButtonTable.row();
menuButtonTable.pack();
stage.addActor(menuButtonTable);
// BOTTOM-RIGHT BUTTON STACK
credits = new Button(skin, "credits");
credits.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
ui.setCurrentScreen(Screens.CREDIT_SCREEN);
}
});
help = new Button(skin, "help");
help.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
ui.setCurrentScreen(Screens.HELP_SCREEN);
}
});
debug = new Button(skin, "debug");
debug.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
DebugScreen debugScr = new DebugScreen();
debugScr.setUI(ui);
ui.setCurrentScreen(debugScr);
}
});
iconStackTable.clear();
iconStackTable.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(), DPIUtils.getPrefButtonSize());
iconStackTable.pad(DPIUtils.getMarginSize() * 2);
if (EngineLogger.debugMode() && world.getCurrentScene() != null) {
iconStackTable.add(debug);
iconStackTable.row();
}
iconStackTable.add(help);
iconStackTable.row();
iconStackTable.add(credits);
iconStackTable.bottom().right();
iconStackTable.setFillParent(true);
iconStackTable.pack();
stage.addActor(iconStackTable);
Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
version.addListener(new ClickListener() {
int count = 0;
long time = System.currentTimeMillis();
public void clicked(InputEvent event, float x, float y) {
if (System.currentTimeMillis() - time < 500) {
count++;
} else {
count = 0;
}
time = System.currentTimeMillis();
if (count == 4) {
EngineLogger.toggle();
if (World.getInstance().isDisposed())
return;
if (EngineLogger.debugMode()) {
iconStackTable.row();
iconStackTable.add(debug);
} else {
Cell<?> cell = iconStackTable.getCell(debug);
iconStackTable.removeActor(debug);
cell.reset();
}
}
}
});
stage.addActor(version);
debug.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
DebugScreen debugScr = new DebugScreen();
debugScr.setUI(ui);
ui.setCurrentScreen(debugScr);
}
});
pointer = new Pointer(skin);
stage.addActor(pointer);
Gdx.input.setInputProcessor(stage);
if (style.musicFile != null) {
music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(style.musicFile));
music.setLooping(true);
music.play();
}
}Example 41
| Project: c2d-engine-master File: GracefulEffectLabel.java View source code |
public void show(boolean isBoss, String text) {
this.clear();
if (isBoss) {
String[] strs = text.split("");
float width = 0;
for (int i = 0; i < strs.length; i++) {
String s = strs[i];
Label temp = new Label(s, new LabelStyle(Engine.resource("Font", BitmapFont.class), Color.WHITE));
temp.setPosition(width, 400);
temp.addAction(Actions.delay(0.1f * i, Actions.sequence(Actions.moveBy(0, -300, 0.5f, Interpolation.swingOut), Actions.delay(1f, Actions.moveBy(0, 300, 0.3f)))));
this.addActor(temp);
width += temp.getPrefWidth();
}
this.setPosition(Engine.getWidth() / 2 - width / 2, 100);
} else {
Label battleLabel = new Label(text, new LabelStyle(Engine.resource("Font", BitmapFont.class), Color.WHITE));
this.setSize(battleLabel.getPrefWidth(), battleLabel.getPrefHeight());
this.setPosition(Engine.getWidth() / 2 - battleLabel.getPrefWidth() / 2, 200);
this.setOrigin(this.getWidth() / 2, this.getHeight() / 2);
this.setScale(0);
this.addAction(sequence(scaleTo(1, 1, 1f, Interpolation.swingOut), delay(1f), Actions.moveBy(50, 0, 0.1f), Actions.moveBy(-1500, 0, 0.3f)));
this.addActor(battleLabel);
}
}Example 42
| Project: comet-pinball-master File: HighscoreScreenImpl.java View source code |
@Override
public void init() {
batch = new SpriteBatch();
atlas = new TextureAtlas("data/menu/button.pack");
skin = new Skin();
skin.addRegions(atlas);
blackFont = new BitmapFont(Gdx.files.internal("data/menu/nueva_black.fnt"), false);
whiteFont = new BitmapFont(Gdx.files.internal("data/menu/nueva_white.fnt"), false);
stage = new Stage();
display.registerHighscoreScreen(this);
}Example 43
| Project: FruitCatcher-master File: HelpScreen.java View source code |
@Override
public void show() {
imageProvider = game.getImageProvider();
backgroundImage = imageProvider.getBackgroundSpring();
buttons = new Button[1];
buttons[0] = new Button(imageProvider.getBack());
camera = new OrthographicCamera();
camera.setToOrtho(false, imageProvider.getScreenWidth(), imageProvider.getScreenHeight());
batch = new SpriteBatch();
buttons[0].setPos(10, 10);
font = new BitmapFont(Gdx.files.internal("fonts/poetsen.fnt"), Gdx.files.internal("fonts/poetsen.png"), false);
startLine = 0;
lineHeight = 30;
lastLineIndex = game.getTextResources().getHelpLines().length - 1;
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true);
}Example 44
| Project: honki_android-master File: MyGdxGame.java View source code |
private void initResources() {
// å?„種リソースã?®èªè¾¼ã?¿
textFont = new BitmapFont(Gdx.files.internal("verdana39.fnt"));
heroTexture = new Texture("UnityChan.png");
finishTexture = new Texture("flag.png");
backgroundTexture = new Texture("bg.png");
backgroundFarTexture = new Texture("bg_far.png");
backgroundNearTexture = new Texture("bg_near.png");
roadTexture = new Texture("road.png");
chipsTexture = new Texture("coins.png");
mineTexture = new Texture("fire.png");
music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
collisionSound = Gdx.audio.newSound(Gdx.files.internal("laser3.mp3"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("coin05.mp3"));
finaleClapsSound = Gdx.audio.newSound(Gdx.files.internal("clapping.mp3"));
// �種制御用クラス�期化
text = new Text(textFont);
hero = new Hero(heroTexture);
background = new Background(backgroundTexture, backgroundFarTexture, backgroundNearTexture, roadTexture);
background.setViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
generator = new Generator(chipsTexture, mineTexture);
}Example 45
| Project: jastroblast-master File: Box2dTest.java View source code |
@Override
public void create() {
world = new World(new Vector2(0, 0), true);
ship = new Ship(world);
debugRenderer = new Box2DDebugRenderer();
camera = new OrthographicCamera();
camera.viewportHeight = 320;
camera.viewportWidth = 480;
camera.position.set(camera.viewportWidth * .5f, camera.viewportHeight * .5f, 0f);
camera.update();
batch = new SpriteBatch();
font = new BitmapFont();
//Ground body
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.position.set(new Vector2(0, 10));
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
// set the ground
groundBox.setAsBox((camera.viewportWidth) * 2, 10.0f);
groundBody.createFixture(groundBox, 0.0f);
//Dynamic Body
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(camera.viewportWidth / 2, camera.viewportHeight / 2);
Body body = world.createBody(bodyDef);
// ball
// CircleShape dynamicCircle = new CircleShape();
// dynamicCircle.setRadius(10f);
// triangle
Vector2[] vertices = new Vector2[3];
vertices[0] = new Vector2(-10, 0);
vertices[1] = new Vector2(10, 0);
vertices[2] = new Vector2(0, 20);
BodyDef triBodyDef = new BodyDef();
triBodyDef.type = BodyType.KinematicBody;
triBodyDef.position.set(new Vector2(camera.viewportWidth / 2 + 5, 100));
//triBodyDef.angle = 1f;
// put the triangle in the world
Body triBody = world.createBody(triBodyDef);
PolygonShape tri = new PolygonShape();
tri.set(vertices);
triBody.createFixture(tri, 0f);
// FixtureDef - properties of the fixture.
// FixtureDef fixtureDef = new FixtureDef();
// fixtureDef.shape = dynamicCircle;
// fixtureDef.density = 15.0f; // how dense it is
// fixtureDef.friction = .9f; // fiction
// fixtureDef.restitution = .15f; // how bouncy
// body.createFixture(fixtureDef);
//
// dynamicCircle.dispose();
tri.dispose();
ship.dispose();
}Example 46
| Project: Point-and-Hit-master File: NoCompassScreen.java View source code |
@Override
public void show() {
stage = new Stage();
table = new Table();
float padding = 50 * scale;
BitmapFont font = new BitmapFont(Gdx.files.internal("fonts/deja_vu_sans_medium.fnt"));
Vector2 screenSize = new Vector2(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
font.setScale(scale);
Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);
messageLabel = new Label(text, labelStyle);
messageLabel.setWrap(true);
messageLabel.setWidth(screenSize.x - padding * 2);
messageLabel.setAlignment(Align.center);
table.setFillParent(true);
table.defaults().pad(padding);
table.add(messageLabel).width(screenSize.x - padding * 2);
stage.addActor(table);
}Example 47
| Project: RogueLike-master File: AssetManager.java View source code |
public static BitmapFont loadFont(String name, int size, Color colour, int borderWidth, Color borderColour, boolean shadow) { String key = name + size + colour.toString() + borderWidth + borderColour.toString(); if (loadedFonts.containsKey(key)) { return loadedFonts.get(key); } FreeTypeFontGenerator fgenerator = new FreeTypeFontGenerator(Gdx.files.internal(name)); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); parameter.size = size; parameter.borderWidth = borderWidth; parameter.kerning = true; parameter.borderColor = borderColour; parameter.borderStraight = true; parameter.color = colour; if (shadow) { parameter.shadowOffsetX = -1; parameter.shadowOffsetY = 1; } BitmapFont font = fgenerator.generateFont(parameter); font.getData().markupEnabled = true; // don't forget to dispose to avoid memory leaks! fgenerator.dispose(); loadedFonts.put(key, font); return font; }
Example 48
| Project: Secludedness-master File: LevelScreen.java View source code |
@Override
public void show() {
super.show();
mTexture = new Texture(Gdx.files.internal("textures/player.png"));
mPlayerTexture = new TextureRegion(mTexture, 0, 0, 64, 64);
mFont = new BitmapFont();
mFont.setColor(1.0f, 0.5f, 1.0f, 1.0f);
// TODO: Change input based on settings
if ((Gdx.app.getType() == ApplicationType.Android) && (Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer))) {
mUsePolling = true;
} else {
mUsePolling = false;
}
mInputManager = new InputManager(mGame, mLevel, mPlayer);
Gdx.input.setInputProcessor(mInputManager);
}Example 49
| Project: Sing-it-now-master File: StartScreen.java View source code |
public void create() {
try {
registerRoom();
} catch (Exception e) {
e.printStackTrace();
}
batch = new SpriteBatch();
background = new Texture("bg_album_art.jpg");
stage = new Stage();
Gdx.input.setInputProcessor(stage);
// A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly
// recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc.
skin = new Skin();
// Generate a 1x1 white texture and store it in the skin named "white".
Pixmap pixmap = new Pixmap(100, 100, Format.RGBA8888);
pixmap.setColor(Color.BLUE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
// Store the default libgdx font under the name "default".
BitmapFont bfont = new BitmapFont();
bfont.getData().setScale(1);
skin.add("default", bfont);
// Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
// Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a name other than "default".
final TextButton textButton = new TextButton("PLAY", textButtonStyle);
textButton.setSize(200, 80);
textButton.setPosition(583, 344);
stage.addActor(textButton);
stage.addActor(textButton);
stage.addActor(textButton);
// Add a listener to the button. ChangeListener is fired when the button's checked state changes, eg when clicked,
// Button#setChecked() is called, via a key press, etc. If the event.cancel() is called, the checked state will be reverted.
// ClickListener could have been used, but would only fire when clicked. Also, canceling a ClickListener event won't
// revert the checked state.
textButton.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
System.out.println("Clicked! Is checked: " + textButton.isChecked());
textButton.setText("Starting new game");
g.setScreen(new RoomScreen(g));
}
});
}Example 50
| Project: spacedebris-master File: GdxGameMain.java View source code |
@Override
public void create() {
screenlist = new Screen[SCREEN_NUMBER];
screenlist[SCREEN_SPLASH] = new SplashScreen(SCREEN_SPLASH);
screenlist[SCREEN_BATTLE] = new BattleScreen();
// Creating global resource managers
queueAssets();
animman = new AnimationManager();
setScreen(screenlist[SCREEN_SPLASH]);
nextscreen = SCREEN_SPLASH;
changescreen = false;
debugtext = new BitmapFont();
batch = new SpriteBatch();
Gdx.app.setLogLevel(Application.LOG_DEBUG);
}Example 51
| Project: tafl-master File: TaflGraphicsService.java View source code |
@Override
public void onFinishLoading() {
Skin skin = getSkin(Assets.Skin.UI_SKIN);
BitmapFont menuFont = getFont(game.deviceSettings.menuFont);
BitmapFont screenTitle = getFont(game.deviceSettings.screenTitleFont);
BitmapFont hudFont = getFont(game.deviceSettings.hudFont);
BitmapFont rulesFont = getFont(game.deviceSettings.rulesFont);
skin.get(Assets.Skin.SKIN_STYLE_MENU, TextButtonStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, TextButtonStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_DIALOG, TextButtonStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, ImageTextButtonStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, ImageTextButtonStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, SelectBoxStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, SelectBoxStyle.class).listStyle.font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, SelectBoxStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, SelectBoxStyle.class).listStyle.font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_DIALOG, WindowStyle.class).titleFont = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, LabelStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_SCREEN_TITLE, LabelStyle.class).font = screenTitle;
skin.get(Assets.Skin.SKIN_STYLE_GAME, LabelStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_DIALOG, LabelStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_PLAYER_TAG, LabelStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_RULES, LabelStyle.class).font = rulesFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, TextFieldStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, TextFieldStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, CheckBoxStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, CheckBoxStyle.class).font = hudFont;
skin.get(Assets.Skin.SKIN_STYLE_MENU, ListStyle.class).font = menuFont;
skin.get(Assets.Skin.SKIN_STYLE_GAME, ListStyle.class).font = hudFont;
}Example 52
| Project: XMLLayoutParser-master File: ExampleGame.java View source code |
/**
* Setups a simple skin without any ressource
*
* @return A simple Skin
*/
private Skin setupSkin() {
Skin skin = new Skin();
Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
skin.add("default", new BitmapFont());
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
LabelStyle labelStyle = new LabelStyle();
labelStyle.font = skin.getFont("default");
labelStyle.fontColor = Color.BLACK;
skin.add("default", labelStyle);
LabelStyle redLabelStyle = new LabelStyle();
redLabelStyle.font = skin.getFont("default");
redLabelStyle.fontColor = Color.RED;
skin.add("red", redLabelStyle);
TextFieldStyle textFieldStyle = new TextFieldStyle();
textFieldStyle.font = skin.getFont("default");
textFieldStyle.fontColor = Color.BLACK;
textFieldStyle.background = skin.newDrawable("white", Color.LIGHT_GRAY);
skin.add("default", textFieldStyle);
return skin;
}Example 53
| Project: hellhopper-master File: ItemBase.java View source code |
public final void renderText(SpriteBatch batch, float visibleAreaPosition, BitmapFont itemFont) {
if (mItemState == TEXT_STATE) {
if (mIsPickedUpTextBoundsDirty) {
TextBounds textBounds = itemFont.getBounds(mPickedUpText);
mPickedUpTextBounds.set(textBounds.width, textBounds.height);
mIsPickedUpTextBoundsDirty = false;
}
float alpha = mTextCountdown / TEXT_COUNTDOWN_DURATION;
Color c = itemFont.getColor();
itemFont.setColor(c.r, c.g, c.b, alpha);
float textX = (mPosition.x + mSize.x / 2.0f) * GameAreaUtils.METER_TO_PIXEL - mPickedUpTextBounds.x / 2.0f;
textX = MathUtils.clamp(textX, 0.0f, HellJump.VIEWPORT_WIDTH - mPickedUpTextBounds.x);
float textY = (mPosition.y + mSize.y / 2.0f - visibleAreaPosition) * GameAreaUtils.METER_TO_PIXEL + mPickedUpTextBounds.y / 2.0f;
itemFont.draw(batch, mPickedUpText, textX, textY);
}
}Example 54
| Project: AIGenesis-master File: SettingsLayer.java View source code |
/**
* Build view elements.
*
*/
private void buildElements() {
Preferences preferences = Gdx.app.getPreferences("pref");
// ---------------------------------------------------------------
// Background.
// ---------------------------------------------------------------
Image image = new Image(background);
image.setWidth(getWidth());
image.setHeight(getHeight());
addActor(image);
// ---------------------------------------------------------------
// Table
// ---------------------------------------------------------------
BitmapFont font = new BitmapFont();
LabelStyle labelStyle = new LabelStyle(font, Color.YELLOW);
final Label titleLabel = new Label("Settings", labelStyle);
CheckBoxStyle checkboxStyle = new CheckBoxStyle();
checkboxStyle.font = font;
final CheckBox checkBox = new CheckBox("", checkboxStyle);
checkBox.setChecked(preferences.getBoolean("audioOn", true));
final Label soundLabel = new Label("Sound", labelStyle);
// SliderStyle sliderStyle = new SliderStyle();
// sliderStyle.knob =
// final Slider slider = new Slider(0, 10, 1, false, sliderStyle);
// slider.setValue(preferences.getInteger("volume", 10));
final Label volumeLabel = new Label("Volume", labelStyle);
final Table table = new Table();
table.size((int) getWidth(), (int) getHeight());
table.add(titleLabel).expandX();
table.row();
table.add(soundLabel).expandY();
checkBox.size(20, 20);
table.add(checkBox);
table.row();
table.add(volumeLabel).expandY().expandX();
// table.add(slider).padRight(100);
table.pack();
addActor(table);
// Handlers
checkBox.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Preferences properties = Gdx.app.getPreferences("pref");
boolean setting = checkBox.isChecked();
properties.putBoolean("audioOn", setting);
properties.flush();
}
});
// slider.setValueChangedListener(new ValueChangedListener()
// {
//
// @Override
// public void changed(Slider slider, float value)
// {
// GameProperties properties = GameProperties.instance();
//
// if (value == 0)
// {
// properties.setVolume(0);
// }
// else
// {
// properties.setVolume(value/10);
// }
// }
// });
}Example 55
| Project: angr-master File: SummaryScreen.java View source code |
/**
* Draw score counters
*/
private void drawScore(SpriteBatch batch) {
BitmapFont font = getFont();
if (!bareScoreCnt.isStopped()) {
bareScoreCnt.update(Gdx.graphics.getDeltaTime());
String str = "" + bareScoreCnt.getValue();
font.draw(batch, str, -(str.length() * font.getSpaceWidth()) / 2.0f, font.getXHeight() + 150.0f);
} else if (!additionalPointsCnt.isStopped()) {
additionalPointsCnt.update(Gdx.graphics.getDeltaTime());
String str = bareScoreCnt.getValue() + " + " + additionalPointsCnt.getValue();
font.draw(batch, str, -(str.length() * font.getSpaceWidth()) / 2.0f, font.getXHeight() + 150.0f);
} else {
String str = bareScoreCnt.getValue() + " + " + additionalPointsCnt.getValue() + scoreText;
font.draw(batch, str, -(str.length() * font.getSpaceWidth()) / 2.0f, font.getXHeight() + 150.0f);
}
}Example 56
| Project: ashley-superjumper-master File: Assets.java View source code |
public static void load() {
background = loadTexture("data/background.png");
backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
items = loadTexture("data/items.png");
mainMenu = new TextureRegion(items, 0, 224, 300, 110);
pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
ready = new TextureRegion(items, 320, 224, 192, 32);
gameOver = new TextureRegion(items, 352, 256, 160, 96);
highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
logo = new TextureRegion(items, 0, 352, 274, 142);
soundOff = new TextureRegion(items, 0, 0, 64, 64);
soundOn = new TextureRegion(items, 64, 0, 64, 64);
arrow = new TextureRegion(items, 0, 64, 64, 64);
pause = new TextureRegion(items, 64, 64, 64, 64);
spring = new TextureRegion(items, 128, 0, 32, 32);
castle = new TextureRegion(items, 128, 64, 64, 64);
coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32), new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
bobHit = new Animation(0.2f, new TextureRegion(items, 128, 128, 32, 32));
squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
platform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16));
breakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16), new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled)
music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.wav"));
coinAnim.setPlayMode(PlayMode.LOOP);
bobJump.setPlayMode(PlayMode.LOOP);
bobFall.setPlayMode(PlayMode.LOOP);
bobHit.setPlayMode(PlayMode.LOOP);
squirrelFly.setPlayMode(PlayMode.LOOP);
platform.setPlayMode(PlayMode.LOOP);
}Example 57
| Project: bbg-gdx-project-setup-master File: Assets.java View source code |
public void unloadAssets(List<String> filenames) {
for (String filename : filenames) {
Object asset = assets.get(filename);
if (asset != null) {
assets.remove(filename);
String assetPath = null;
if (asset.getClass() == Sprite.class) {
assetPath = imageFilePath(filename);
} else if (asset.getClass() == BitmapFont.class) {
assetPath = fontFilePath(filename);
} else if (asset.getClass() == Sound.class) {
assetPath = sfxFilePath(filename);
} else if (asset.getClass() == Music.class) {
assetPath = musicFilePath(filename);
}
if (assetPath != null) {
assetManager.unload(assetPath);
}
}
}
}Example 58
| Project: droidtowers-master File: DroidTowersGame.java View source code |
public void render() {
Gdx.gl.glClearColor(0.48f, 0.729f, 0.870f, 1.0f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glEnable(GL10.GL_TEXTURE_2D);
float deltaTime = Gdx.graphics.getDeltaTime();
SceneManager.activeScene().getCamera().update();
ActionManager.instance().update(deltaTime);
InputSystem.instance().update(deltaTime);
PathSearchManager.instance().update(deltaTime);
TweenSystem.manager().update((int) (deltaTime * 1000 * SceneManager.activeScene().getTimeMultiplier()));
if (soundController != null) {
soundController.update(deltaTime);
}
spriteBatch.setProjectionMatrix(SceneManager.activeScene().getCamera().combined);
if (frameBuffer != null) {
frameBuffer.begin();
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
SceneManager.activeScene().render(deltaTime);
frameBuffer.end();
spriteBatchFBO.begin();
spriteBatchFBO.draw(frameBuffer.getColorBufferTexture(), 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 0, 0, 1, 1);
spriteBatchFBO.end();
} else {
SceneManager.activeScene().render(deltaTime);
}
SceneManager.activeScene().getStage().act(deltaTime);
SceneManager.activeScene().getStage().draw();
if (rootUiStage.getActors().size > 0) {
rootUiStage.act(deltaTime);
rootUiStage.draw();
}
//noinspection PointlessBooleanExpression
if (DEBUG && DISPLAY_DEBUG_INFO) {
Table.drawDebug(SceneManager.activeScene().getStage());
Table.drawDebug(rootUiStage);
float javaHeapInBytes = Gdx.app.getJavaHeap() / TowerConsts.ONE_MEGABYTE;
float nativeHeapInBytes = Gdx.app.getNativeHeap() / TowerConsts.ONE_MEGABYTE;
timeUntilDebugInfoUpdate -= deltaTime;
if (timeUntilDebugInfoUpdate <= 0f) {
timeUntilDebugInfoUpdate = 3f;
debugInfo.delete(0, debugInfo.length());
debugInfo.append("fps: ");
debugInfo.append(Gdx.graphics.getFramesPerSecond());
debugInfo.append("\nmem: (java ");
debugInfo.append((int) javaHeapInBytes);
debugInfo.append("Mb, heap: ");
debugInfo.append((int) nativeHeapInBytes);
debugInfo.append("Mb, gpu: ");
debugInfo.append((int) TowerAssetManager.assetManager().getMemoryInMegabytes());
debugInfo.append("Mb)");
debugInfo.append(" psm: ");
debugInfo.append(PathSearchManager.instance().queueLength());
}
spriteBatch.begin();
BitmapFont font = FontManager.Roboto12.getFont();
font.setColor(Color.BLACK);
font.drawMultiLine(spriteBatch, debugInfo, 6, 35);
font.setColor(Color.CYAN);
font.drawMultiLine(spriteBatch, debugInfo, 5, 36);
font.setColor(Color.WHITE);
spriteBatch.end();
}
}Example 59
| Project: eadventure-master File: RuntimeFont.java View source code |
public boolean loadAsset() {
super.loadAsset();
String fileName = null;
if (descriptor.getUri() != null) {
fileName = descriptor.getUri();
}
String fontData = defaultFont;
String fontPng = defaultFontPng;
AssetHandlerImpl ah = (AssetHandlerImpl) assetHandler;
FileHandle fntHandle = ah.getFileHandle(fileName + ".fnt");
FileHandle pngHandle = ah.getFileHandle(fileName + ".png");
if (fntHandle.exists() && pngHandle.exists()) {
fontData = fileName + ".fnt";
fontPng = fileName + ".png";
}
Texture texture = new Texture(ah.getFileHandle(fontPng), true);
texture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);
bitmapFont = new BitmapFont(ah.getFileHandle(fontData), new TextureRegion(texture), true);
return true;
}Example 60
| Project: examensarbete-master File: Resources.java View source code |
public void load() {
mManager.load("data/fonts/hud.fnt", BitmapFont.class);
mManager.load("obj/level/level_xlarge.g3db", Model.class);
mManager.load("obj/level/level_xlarge_vis.g3db", Model.class);
mManager.load("obj/player/wep/LaserWeapon.g3db", Model.class);
mManager.load("obj/player/animated/player_animated.g3db", Model.class);
mManager.load("obj/player/wep/Grenade.g3db", Model.class);
mManager.load("obj/skybox/spacesphere.obj", Model.class);
mManager.load("tex/laser/laser_middle_b.png", Texture.class);
mManager.load("tex/bullethole.png", Texture.class);
mManager.load("tex/teamtag_oc.png", Texture.class);
mManager.load("tex/teamtag_m.png", Texture.class);
mManager.load("sfx/sound/lasershot.wav", Sound.class);
mManager.load("sfx/music/menutheme.mp3", Music.class);
mManager.load("sfx/music/theme.mp3", Music.class);
mManager.load("tex/particle/blood.p", ParticleEffect.class);
mManager.load("tex/particle/ptest.p", ParticleEffect.class);
Bullet.init();
}Example 61
| Project: explorerRPG-master File: BaseButton.java View source code |
@Override
public void setText(String text) {
if (text != this.text) {
this.text = text;
// setup font
{
font = new BitmapFont();
while (font.getScaleX() > 0.1f && font.getBounds(text).width > width - 10) {
font.setScale(font.getScaleX() - 0.1f);
}
}
float textWidth = font.getBounds(text).width;
textX = width * 0.5f - textWidth * 0.5f;
float textHeight = font.getLineHeight() * font.getScaleY();
textY = height * 0.5f + textHeight * 0.5f;
}
}Example 62
| Project: fappy-bird-master File: FappyBird.java View source code |
@Override
public void create() {
FONT_WHITE = new BitmapFont(Gdx.files.internal("data/font_white.fnt"), Gdx.files.internal("data/font_white.png"), false);
FONT_BLACK = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
FONT_BLACK.setScale(2.5f);
FONT_WHITE.setScale(2.5f);
Animation birdAnimation = new Animation(0.3f, new TextureRegion(new Texture(Gdx.files.internal(IMAGE_BIRD_1))), new TextureRegion(new Texture(Gdx.files.internal(IMAGE_BIRD_2))), new TextureRegion(new Texture(Gdx.files.internal(IMAGE_BIRD_3))), new TextureRegion(new Texture(Gdx.files.internal(IMAGE_BIRD_2))));
birdAnimation.setPlayMode(Animation.LOOP);
this.batch = new SpriteBatch();
this.drawables = new ArrayList<Drawable>();
this.pipeFactory = new PipeFactory(Gdx.files.internal(IMAGE_PIPE), Gdx.files.internal(IMAGE_PIPE_TOP), SCROLL_SPEED_FLOOR);
this.bird = new Bird(birdAnimation);
this.floor = new Background(Gdx.files.internal(IMAGE_FLOOR), SCROLL_SPEED_FLOOR);
drawables.add(new Background(Gdx.files.internal(IMAGE_BACKGROUND), SCROLL_SPEED_BACKGROUND));
drawables.add(pipeFactory);
drawables.add(bird);
drawables.add(floor);
}Example 63
| Project: gdx-autumn-mvc-master File: SkinService.java View source code |
private static void loadFonts(final String atlasPath, final String[] fontPaths, final AssetService assetService) {
if (fontPaths.length != 0) {
final BitmapFontParameter loadingParameters = new BitmapFontParameter();
loadingParameters.atlasName = atlasPath;
for (final String fontPath : fontPaths) {
assetService.finishLoading(fontPath, BitmapFont.class, loadingParameters);
}
}
}Example 64
| Project: Hakd-master File: Hakd.java View source code |
private void loadAssets() {
assets.load("nTextures.txt", TextureAtlas.class);
assets.load("lTextures.txt", TextureAtlas.class);
assets.load("skins/uiskin.json", Skin.class);
// text font
assets.load("skins/font/Fonts_7.fnt", BitmapFont.class);
// console font
assets.load("skins/font/Fonts_0.fnt", BitmapFont.class);
assets.finishLoading();
BitmapFont textFont = assets.get("skins/font/Fonts_7.fnt", BitmapFont.class);
textFont.setColor(new Color(1.0f, 1.0f, 1.0f, 1.0f));
textFont.setScale(.6f);
BitmapFont consoleFont = assets.get("skins/font/Fonts_0.fnt", BitmapFont.class);
consoleFont.setColor(new Color(0.0f, 0.7f, 0.0f, 1.0f));
consoleFont.setScale(.6f);
// set texture filters
assets.get("nTextures.txt", TextureAtlas.class).findRegion("black").getTexture().setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
textFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
consoleFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
assets.get("skins/uiskin.json", Skin.class).getAtlas().findRegion("default").getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
}Example 65
| Project: it.alcacoop.fourinaline-master File: FourInALine.java View source code |
@Override
public void create() {
Instance = this;
optionPrefs = Gdx.app.getPreferences("Options");
matchOptionPrefs = Gdx.app.getPreferences("MatchOptions");
gameOptionPrefs = Gdx.app.getPreferences("GameOptions");
snd = new SoundManager();
// CHECK SCREEN DIM AND SELECT CORRECT ATLAS
int pWidth = Gdx.graphics.getWidth();
if (pWidth <= 480)
ss = 2;
else if (pWidth <= 800)
ss = 1;
else
ss = 0;
resolution = resolutions[ss];
atlas = new TextureAtlas(Gdx.files.internal(resname[ss] + "/pack.atlas"));
skin = new Skin(Gdx.files.internal(resname[ss] + "/myskin.json"));
font = new BitmapFont(Gdx.files.internal(resname[ss] + "/checker.fnt"), false);
font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
wood = new Texture(Gdx.files.internal(resname[ss] + "/texture.jpg"));
mask = new Texture(Gdx.files.internal(resname[ss] + "/mask.png"));
btntxt = new Texture(Gdx.files.internal(resname[ss] + "/btn_texture.jpg"));
transitionTimer = new Timer();
menuScreen = new MenuScreen();
gameScreen = new GameScreen();
matchOptionsScreen = new MatchOptionsScreen();
optionsScreen = new OptionsScreen();
board = new Board(7, 6, 4, gameScreen.getStage().getHeight() * 0.76f);
board.setPosition(-gameScreen.getStage().getWidth(), (gameScreen.getStage().getHeight() - board.getHeight()) / 2);
gameScreen.getStage().addActor(board);
fsm = new FSM();
setScreen(new SplashScreen(resname[ss] + "/alca.png"));
}Example 66
| Project: jumper-master File: Assets.java View source code |
public static void load() {
background = loadTexture("data/background.png");
backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
items = loadTexture("data/items.png");
mainMenu = new TextureRegion(items, 0, 224, 300, 110);
pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
ready = new TextureRegion(items, 320, 224, 192, 32);
gameOver = new TextureRegion(items, 352, 256, 160, 96);
highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
logo = new TextureRegion(items, 0, 352, 274, 142);
soundOff = new TextureRegion(items, 0, 0, 64, 64);
soundOn = new TextureRegion(items, 64, 0, 64, 64);
arrow = new TextureRegion(items, 0, 64, 64, 64);
pause = new TextureRegion(items, 64, 64, 64, 64);
spring = new TextureRegion(items, 128, 0, 32, 32);
castle = new TextureRegion(items, 128, 64, 64, 64);
coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32), new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
bobHit = new TextureRegion(items, 128, 128, 32, 32);
squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
platform = new TextureRegion(items, 64, 160, 64, 16);
brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16), new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled)
music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.wav"));
}Example 67
| Project: libgdx-demo-superjumper-master File: Assets.java View source code |
public static void load() {
background = loadTexture("data/background.png");
backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
items = loadTexture("data/items.png");
mainMenu = new TextureRegion(items, 0, 224, 300, 110);
pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
ready = new TextureRegion(items, 320, 224, 192, 32);
gameOver = new TextureRegion(items, 352, 256, 160, 96);
highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
logo = new TextureRegion(items, 0, 352, 274, 142);
soundOff = new TextureRegion(items, 0, 0, 64, 64);
soundOn = new TextureRegion(items, 64, 0, 64, 64);
arrow = new TextureRegion(items, 0, 64, 64, 64);
pause = new TextureRegion(items, 64, 64, 64, 64);
spring = new TextureRegion(items, 128, 0, 32, 32);
castle = new TextureRegion(items, 128, 64, 64, 64);
coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32), new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
bobHit = new TextureRegion(items, 128, 128, 32, 32);
squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
platform = new TextureRegion(items, 64, 160, 64, 16);
brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16), new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled)
music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.wav"));
}Example 68
| Project: libgdx-easy-master File: StyleAtlas.java View source code |
public BitmapFont read(Json json, JsonValue jsonData, Class type) { String path = json.readValue("file", String.class, jsonData); FileHandle fontFile = skinFile.parent().child(path); if (!fontFile.exists()) fontFile = Gdx.files.internal(path); if (!fontFile.exists()) throw new SerializationException("Font file not found: " + fontFile); // Use a region with the same name as the font, else use // a PNG file in the same directory as the FNT file. String regionName = fontFile.nameWithoutExtension(); try { TextureRegion region = skin.optional(regionName, TextureRegion.class); if (region != null) return new BitmapFont(fontFile, region, false); else { FileHandle imageFile = fontFile.parent().child(regionName + ".png"); if (imageFile.exists()) return new BitmapFont(fontFile, imageFile, false); else return new BitmapFont(fontFile, false); } } catch (RuntimeException ex) { throw new SerializationException("Error loading bitmap font: " + fontFile, ex); } }
Example 69
| Project: libgdx-gameservices-tutorial-master File: Assets.java View source code |
public static void load() {
background = loadTexture("data/background.png");
backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
items = loadTexture("data/items.png");
mainMenu = new TextureRegion(items, 0, 224, 300, 110);
pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
ready = new TextureRegion(items, 320, 224, 192, 32);
gameOver = new TextureRegion(items, 352, 256, 160, 96);
highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
logo = new TextureRegion(items, 0, 352, 274, 142);
soundOff = new TextureRegion(items, 0, 0, 64, 64);
soundOn = new TextureRegion(items, 64, 0, 64, 64);
arrow = new TextureRegion(items, 0, 64, 64, 64);
pause = new TextureRegion(items, 64, 64, 64, 64);
spring = new TextureRegion(items, 128, 0, 32, 32);
castle = new TextureRegion(items, 128, 64, 64, 64);
coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32), new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
bobHit = new TextureRegion(items, 128, 128, 32, 32);
squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
platform = new TextureRegion(items, 64, 160, 64, 16);
brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16), new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled)
music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.wav"));
}Example 70
| Project: libgdxMultiplayerSuperJumper-master File: Assets.java View source code |
public static void load() {
background = loadTexture(prefix + "background.png");
backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
items = loadTexture(prefix + "items.png");
multiplayer = loadTexture(prefix + "multiplayer.png");
enemyBob = loadTexture(prefix + "monster2.png");
mainMenu = new TextureRegion(items, 0, 224, 300, 110);
pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
ready = new TextureRegion(items, 320, 224, 192, 32);
gameOver = new TextureRegion(items, 352, 256, 160, 96);
highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
logo = new TextureRegion(items, 0, 352, 274, 142);
soundOff = new TextureRegion(items, 0, 0, 64, 64);
soundOn = new TextureRegion(items, 64, 0, 64, 64);
arrow = new TextureRegion(items, 0, 64, 64, 64);
pause = new TextureRegion(items, 64, 64, 64, 64);
spring = new TextureRegion(items, 128, 0, 32, 32);
castle = new TextureRegion(items, 128, 64, 64, 64);
coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32), new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
bobHit = new TextureRegion(items, 128, 128, 32, 32);
squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
platform = new TextureRegion(items, 64, 160, 64, 16);
brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16), new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
font = new BitmapFont(Gdx.files.internal(prefix + "font.fnt"), Gdx.files.internal(prefix + "font.png"), false);
music = Gdx.audio.newMusic(Gdx.files.internal(prefix + "music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled)
music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal(prefix + "jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal(prefix + "highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal(prefix + "hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal(prefix + "coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal(prefix + "click.wav"));
FileHandle file = Gdx.files.internal(prefix + "platform.data");
platformDataString = file.readString();
}Example 71
| Project: nahwc-g-master File: Assets.java View source code |
public void initMainMenu() {
atlas = new TextureAtlas(Gdx.files.internal(TEXTURE_ATLAS_LOC));
checked = atlas.findRegion(CHECKED_REGION_STRING);
unchecked = atlas.findRegion(UNCHECKED_REGION_STRING);
background = atlas.findRegion(BACKGROUN_REGION_STRING);
knob = atlas.findRegion(KNOB_REGION_STRING);
titleSprite = atlas.createSprite(TITLE_REGION_STRING);
levelOnePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_ONE_REGION_STRING));
levelTwoPreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_TWO_REGION_STRING));
levelThreePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_THREE_REGION_STRING));
levelFourPreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_FOUR_REGION_STRING));
levelFivePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_FIVE_REGION_STRING));
patchBox = new NinePatch(atlas.createPatch(PATCH_BOX_REGION_STRING));
finePrint = new BitmapFont(Gdx.files.internal(FINE_PRINT));
font = new BitmapFont(Gdx.files.internal(FONT_LOC));
}Example 72
| Project: overlap2d-master File: SplashScreen.java View source code |
@Override
public void create() {
atlas = new TextureAtlas(Gdx.files.internal("splash/splash.atlas"));
stage = new Stage();
NinePatch backgroundPatch = getNinePatch(atlas.findRegion("background"));
Image background = new Image(backgroundPatch);
background.setWidth(stage.getWidth() + 2);
background.setX(-1);
background.setY(-1);
stage.addActor(background);
Image graphic = new Image(atlas.findRegion("graphic"));
graphic.setX(stage.getWidth() / 2 - graphic.getWidth() / 2);
graphic.setY(stage.getHeight() - graphic.getHeight() - 37);
stage.addActor(graphic);
Image logo = new Image(atlas.findRegion("logo"));
logo.setX(stage.getWidth() / 2 - logo.getWidth() / 2);
logo.setY(graphic.getY() - logo.getHeight() - 3);
stage.addActor(logo);
progressBarBg = new Image(getNinePatch(atlas.findRegion("progressBg")));
progressBar = new Image(getNinePatch(atlas.findRegion("progressBar")));
progressBarBg.setWidth(stage.getWidth() - 24);
progressBarBg.setX(stage.getWidth() / 2 - progressBarBg.getWidth() / 2);
progressBarBg.setY(89);
progressBar.setWidth(6);
progressBar.setX(progressBarBg.getX());
progressBar.setY(progressBarBg.getY());
stage.addActor(progressBarBg);
stage.addActor(progressBar);
Image separator = new Image(atlas.findRegion("devider"));
separator.setScaleX(stage.getWidth() - 24);
separator.setX(stage.getWidth() / 2 - separator.getScaleX() / 2);
separator.setY(61);
stage.addActor(separator);
BitmapFont robotFont = new BitmapFont(Gdx.files.internal("splash/roboto.fnt"));
Label.LabelStyle labelStyle = new Label.LabelStyle(robotFont, new Color(224f / 255f, 224f / 255f, 224f / 255f, 1f));
Label companyName = new Label("Underwater Apps LLC", labelStyle);
companyName.setX(13);
companyName.setY(separator.getY() - companyName.getHeight() - 7);
stage.addActor(companyName);
Label copyright = new Label("Copyright (c) 2015. All rights reserved.", labelStyle);
copyright.setX(13);
copyright.setY(companyName.getY() - 20);
stage.addActor(copyright);
Label version = new Label("v 0.0.9", labelStyle);
version.setX(stage.getWidth() - 13 - version.getWidth());
version.setY(companyName.getY());
stage.addActor(version);
progress = new Label("Loading fonts", labelStyle);
progress.setX(stage.getWidth() / 2 - progress.getWidth() / 2);
progress.setY(progressBar.getY() + 11);
stage.addActor(progress);
percent = new Label("55%", labelStyle);
percent.setX(stage.getWidth() - 13 - percent.getWidth());
percent.setY(progressBar.getY() + 11);
stage.addActor(percent);
Image logoLbl = new Image(atlas.findRegion("logoText"));
logoLbl.setX(stage.getWidth() / 2 - logoLbl.getWidth() / 2);
logoLbl.setY(stage.getHeight() - 24);
stage.addActor(logoLbl);
setProgress(0);
setProgressStatus("Initializing");
loadData();
}Example 73
| Project: puyopuyo-master File: GameScreenPortrait.java View source code |
protected void initGraphics() {
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
controller = new Controller(gameLogic, this, stage, new Vector2(0, 0), new Vector2(VIRTUAL_WIDTH, VIRTUAL_HEIGHT));
gridActor = new GridActor(PweekMini.getInstance().atlasPuyo, gameLogic, PweekMini.getInstance().manager.get("images/font_score.fnt", BitmapFont.class), 148, 130, 50, puyoSize);
ExplosionActor explosionActor = new ExplosionActor(PweekMini.getInstance().atlasPuyo, gameLogic, PweekMini.getInstance().manager.get("images/font_score.fnt", BitmapFont.class), 148, 130, 50, puyoSize);
nextPieceActor = new NextPieceActor(PweekMini.getInstance().atlasPuyo, gameLogic, 21, 590, puyoSize);
ScoreActor scoreActor = new ScoreActor(PweekMini.getInstance().manager.get("images/font_score.fnt", BitmapFont.class), gameLogic, 300, 786);
HighScoreActor highScoreActor = new HighScoreActor(PweekMini.getInstance().manager.get("images/font_score.fnt", BitmapFont.class), this, 76, 440);
TextureRegion pauseRegion = new TextureRegion(PweekMini.getInstance().atlasBouttons.findRegion("pause_button"));
stage.addActor(new Image(new TextureRegion(PweekMini.getInstance().manager.get("images/background.png", Texture.class), 480, 800)));
stage.addActor(new PortraitPanelActor(PweekMini.getInstance().atlasPanelsPortrait));
stage.addActor(gridActor);
stage.addActor(nextPieceActor);
stage.addActor(scoreActor);
stage.addActor(highScoreActor);
stage.addActor(explosionActor);
pauseButton = new PauseButton(pauseRegion);
addButton(pauseButton, 10, VIRTUAL_HEIGHT - 10 - pauseRegion.getRegionHeight());
addButton(MusicButtonActor.createMusicButton(PweekMini.getInstance().atlasBouttons), VIRTUAL_WIDTH - 64, VIRTUAL_HEIGHT - 64);
addButton(SoundButtonActor.createSoundButton(PweekMini.getInstance().atlasBouttons), VIRTUAL_WIDTH - 2 * 64 - 10, VIRTUAL_HEIGHT - 64);
boolean show = false;
if (gameOver != null) {
show = gameOver.isVisible();
}
gameOver = new GameOverActor(PweekMini.getInstance().atlasPlank, PweekMini.getInstance().atlasPanelsPortrait, PweekMini.getInstance().atlasBouttons, PweekMini.getInstance().manager.get("images/font_score.fnt", BitmapFont.class), this, VIRTUAL_WIDTH / 2, 2 * VIRTUAL_HEIGHT / 3);
stage.addActor(gameOver);
if (show) {
gameOver();
} else {
gameOver.hide();
}
pauseMenu = new PauseMenu(PweekMini.getInstance().atlasPlank, this, PweekMini.getInstance().getHandler(), ScreenOrientation.PORTRAIT, !gamePaused);
stage.addActor(pauseMenu);
show = true;
if (startActor != null) {
show = startActor.isVisible();
}
startActor = new StartActor(PweekMini.getInstance().atlasPlank, this);
stage.addActor(startActor);
if (show) {
startActor.show();
} else {
startActor.setVisible(false);
startActor.setTouchable(Touchable.disabled);
if (gamePaused) {
pauseMenu.show();
}
}
}Example 74
| Project: StickFlick-master File: Options.java View source code |
@Override
public void show() {
batch = new SpriteBatch();
atlas = new TextureAtlas("data/Textures.atlas");
skin = new Skin();
skin.addRegions(atlas);
white = new BitmapFont(Gdx.files.internal("data/whiteFont.fnt"), false);
buttonClick = Gdx.audio.newSound(Gdx.files.internal("data/sounds/button2.mp3"));
//Set Volumes
SFXVolume = prefs.getInteger("SFXVolume") * 0.01f;
}Example 75
| Project: SuperJumper-master File: Assets.java View source code |
public static void load() {
background = loadTexture("data/background.png");
backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
items = loadTexture("data/items.png");
mainMenu = new TextureRegion(items, 0, 224, 300, 110);
pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
ready = new TextureRegion(items, 320, 224, 192, 32);
gameOver = new TextureRegion(items, 352, 256, 160, 96);
highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
logo = new TextureRegion(items, 0, 352, 274, 142);
soundOff = new TextureRegion(items, 0, 0, 64, 64);
soundOn = new TextureRegion(items, 64, 0, 64, 64);
arrow = new TextureRegion(items, 0, 64, 64, 64);
pause = new TextureRegion(items, 64, 64, 64, 64);
spring = new TextureRegion(items, 128, 0, 32, 32);
castle = new TextureRegion(items, 128, 64, 64, 64);
coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32), new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
bobHit = new TextureRegion(items, 128, 128, 32, 32);
squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
platform = new TextureRegion(items, 64, 160, 64, 16);
brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16), new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled)
music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.wav"));
}Example 76
| Project: Taller_Space_Invaders-master File: spaceInvaders.java View source code |
@Override
public void create() {
manager = new AssetManager();
// Es recomendable solo usar un SpriteBatch en todo el juego
batch = new SpriteBatch();
this.font = new BitmapFont(Gdx.files.internal("data/arial.fnt"), Gdx.files.internal("data/arial.png"), false);
// Obtenemos los datos del fichero, o si no está creado, se crea automaticamente
preferencias = Gdx.app.getPreferences("-_PreferencesInvaders-Data-_");
// Pantallas de carga del juego
LOADING = new LoadingScreen(this);
// Cargamos todos los elementos externos que usará el juego, como son las texturas y los sonidos.
manager.load("data/Loading.png", Texture.class);
manager.load("data/Background.png", Texture.class);
manager.load("data/GameOver.png", Texture.class);
manager.load("data/Records.png", Texture.class);
manager.load("data/BotonPlay.png", Texture.class);
manager.load("data/BotonExit.png", Texture.class);
manager.load("data/BotonRecords.png", Texture.class);
manager.load("data/Win.png", Texture.class);
manager.load("data/alien1.png", Texture.class);
manager.load("data/alien2.png", Texture.class);
manager.load("data/alien3.png", Texture.class);
manager.load("data/alien4.png", Texture.class);
manager.load("data/naveAlienBonus.png", Texture.class);
manager.load("data/ship.png", Texture.class);
manager.load("data/shot.png", Texture.class);
manager.load("data/shotAlien.png", Texture.class);
manager.load("data/balaza.png", Texture.class);
manager.load("data/bolaBalaEspecial.png", Texture.class);
manager.load("data/explosion.wav", Sound.class);
manager.load("data/shot.wav", Sound.class);
// Coloca la pantalla actual, se llama desde cualquier pantalla anterior y se llama a Screen.show desde la nueva pantalla
setScreen(LOADING);
}Example 77
| Project: TerraLegion-master File: ResourceManager.java View source code |
public void dispose() {
Iterator it = textures.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
((Texture) pair.getValue()).dispose();
// avoids a ConcurrentModificationException
it.remove();
}
it = fonts.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
((BitmapFont) pair.getValue()).dispose();
// avoids a ConcurrentModificationException
it.remove();
}
}Example 78
| Project: Unsealed-master File: AbstractChapter.java View source code |
public void show() {
super.show();
act = 0;
// Load the tmx file into map
tileMap = TiledLoader.createMap(Gdx.files.internal("map-atlases/" + mapname + ".tmx"));
// Load the tiles into atlas
tileAtlas = new TileAtlas(tileMap, Gdx.files.internal("map-atlases/"));
// Create the renderer
tileMapRenderer = new TileMapRenderer(tileMap, tileAtlas, tileMap.width, tileMap.height);
// Create the camera
camera = new OrthographicCamera(MENU_VIEWPORT_WIDTH, MENU_VIEWPORT_HEIGHT);
camera.position.set(this.stage.getWidth() / 2, this.stage.getHeight() / 2, 0);
NinePatch patch = getAtlas().createPatch("maps/dialog-box");
textBoxStyle = new StyledTable.TableStyle();
textBoxStyle.background = new NinePatchDrawable(patch);
textBoxStyle.font = new BitmapFont();
textBoxStyle.padX = 8;
textBoxStyle.padY = 4;
characters = new ArrayList<MapCharacter>();
stage.setCamera(camera);
dialog = new TextBox("", textBoxStyle);
dialog.setWidth(Gdx.graphics.getWidth());
dialog.setHeight(Gdx.graphics.getHeight() / 4);
dialog.setVisible(false);
hud.addActor(dialog);
Gdx.input.setInputProcessor(new InputMultiplexer(this, hud));
}Example 79
| Project: Catroid-maven-playground-deprecated-master File: StageListener.java View source code |
public void create() {
font = new BitmapFont();
font.setColor(1f, 0f, 0.05f, 1f);
font.setScale(1.2f);
pathForScreenshot = Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()) + "/";
costumeComparator = new CostumeComparator();
project = ProjectManager.getInstance().getCurrentProject();
virtualWidth = project.virtualScreenWidth;
virtualHeight = project.virtualScreenHeight;
virtualWidthHalf = virtualWidth / 2;
virtualHeightHalf = virtualHeight / 2;
screenMode = ScreenModes.STRETCH;
stage = new Stage(virtualWidth, virtualHeight, true);
batch = stage.getSpriteBatch();
camera = (OrthographicCamera) stage.getCamera();
camera.position.set(0, 0, 0);
sprites = project.getSpriteList();
for (Sprite sprite : sprites) {
stage.addActor(sprite.costume);
}
if (DEBUG) {
OrthoCamController camController = new OrthoCamController(camera);
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(camController);
multiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(multiplexer);
fpsLogger = new FPSLogger();
} else {
Gdx.input.setInputProcessor(stage);
}
background = new Texture(Gdx.files.internal("stage/white_pixel.bmp"));
axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp"));
}Example 80
| Project: Drone-SWE12-deprecated-master File: StageListener.java View source code |
public void create() {
font = new BitmapFont();
font.setColor(1f, 0f, 0.05f, 1f);
font.setScale(1.2f);
pathForScreenshot = Utils.buildProjectPath(ProjectManager.getInstance().getCurrentProject().getName()) + "/";
costumeComparator = new CostumeComparator();
project = ProjectManager.getInstance().getCurrentProject();
virtualWidth = project.virtualScreenWidth;
virtualHeight = project.virtualScreenHeight;
virtualWidthHalf = virtualWidth / 2;
virtualHeightHalf = virtualHeight / 2;
screenMode = ScreenModes.STRETCH;
stage = new Stage(virtualWidth, virtualHeight, true);
batch = stage.getSpriteBatch();
camera = (OrthographicCamera) stage.getCamera();
camera.position.set(0, 0, 0);
sprites = project.getSpriteList();
for (Sprite sprite : sprites) {
stage.addActor(sprite.costume);
}
if (DEBUG) {
OrthoCamController camController = new OrthoCamController(camera);
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(camController);
multiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(multiplexer);
fpsLogger = new FPSLogger();
} else {
Gdx.input.setInputProcessor(stage);
}
background = new Texture(Gdx.files.internal("stage/white_pixel.bmp"));
axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp"));
}Example 81
| Project: CatchDROP-master File: SettingsScreen.java View source code |
public void init(final CDGame game) {
camera = game.camera;
stage = new Stage();
Gdx.input.setInputProcessor(stage);
headerFont = game.assManager.get("heading.ttf", BitmapFont.class);
btnFont = game.assManager.get("size20.ttf", BitmapFont.class);
skin = new Skin();
pixmap = new Pixmap(1, 1, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
pixtexture = new Texture(pixmap);
skin.add("white", pixtexture);
skin.add("heading", headerFont);
skin.add("normalfont", btnFont);
skin.add("btnFontColor", Color.BLACK);
skin.add("default", new BitmapFont());
LabelStyle lblStyle = new LabelStyle();
lblStyle.font = skin.getFont("heading");
skin.add("default", lblStyle);
TextButtonStyle btnStyle = new TextButtonStyle();
btnStyle.up = skin.newDrawable("white", Color.GRAY);
btnStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
btnStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
btnStyle.checked = skin.newDrawable("white", Color.WHITE);
btnStyle.font = skin.getFont("normalfont");
btnStyle.fontColor = skin.getColor("btnFontColor");
skin.add("default", btnStyle);
Label scrTitle = new Label("Game Settings", skin);
gameModeSetting = new TextButton("Game Mode: " + game.gameModeStr, skin);
autoPauseSetting = new TextButton("Auto-Pause: " + game.autoPauseStr, skin);
dragSetting = new TextButton("Dragging: " + game.dragStr, skin);
if (game.autoPause)
autoPauseSetting.setChecked(true);
else
autoPauseSetting.setChecked(false);
if (game.noDrag)
dragSetting.setChecked(false);
else
dragSetting.setChecked(true);
TextButton showCHSBtn = new TextButton("Classic Highscores", skin);
TextButton showZHSBtn = new TextButton("Zen Highscores", skin);
TextButton showAchievements = new TextButton("Show Achievements", skin);
TextButton backBtn = new TextButton("Back", skin);
gameModeSetting.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown) {
/*
System.out.println("Setting Clicked!");
GameScreen[] gameModes = {
new ZenGame(game),
new ClassicGame(game)
};
if(gmIndex>gameModes.length-1) {
gmIndex = 0;
}
game.gScr = gameModes[gmIndex];
gmIndex++;
System.out.println("Game mode index: "+gmIndex);
System.out.println("Game mode: "+game.gameModeStr);
System.out.println("Game mode: "+game.gScr);
// */
}
}
});
autoPauseSetting.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown) {
System.out.println("Setting Clicked!");
if (game.autoPause) {
game.autoPause = false;
} else {
game.autoPause = true;
}
}
}
});
dragSetting.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown) {
System.out.println("Setting Clicked!");
if (game.noDrag) {
game.noDrag = false;
} else {
game.noDrag = true;
}
}
}
});
backBtn.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown)
game.setScreen(backScreen);
}
});
showCHSBtn.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown)
CDGame.googleServices.showClassicScores();
}
});
showZHSBtn.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown)
CDGame.googleServices.showZenScores();
}
});
showAchievements.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (shown)
CDGame.googleServices.showAchievements();
}
});
table = new Table();
table.add(scrTitle).pad(10);
table.row();
//table.add(gameModeSetting).width(300).height(50).pad(5);
table.row();
if (game.usingDesktop) {
table.add(autoPauseSetting).width(300).height(50).pad(5);
table.row();
table.add(dragSetting).width(300).height(50).pad(5);
table.row();
}
if (// Let's hide these from desktop for now until we have a working leaderboard system for desktop version.
!game.usingDesktop) {
table.add(showCHSBtn).width(300).height(50).pad(5);
table.row();
table.add(showZHSBtn).width(300).height(50).pad(5);
table.row();
}
table.add(backBtn).width(300).height(50).pad(5);
table.setPosition(game.GAME_WIDTH / 2, game.GAME_HEIGHT / 2);
stage.addActor(table);
game.initedSettings = true;
}Example 82
| Project: Dodge-The-Cars-master File: Art.java View source code |
/**
* Loads assets for game.
*/
public static void load() {
// splash screen images
splashScreenTexture = loadTexture(ASSET_TEXTURE_SPLASHSCREEN);
titleScreenTexture = loadTexture(ASSET_TEXTURE_TITLESCREEN);
sturdyHelmetLogoTex = new TextureRegion(splashScreenTexture);
splashBackgroundTex = new TextureRegion(splashScreenTexture, 5, 5);
// load textures
backgroundTexture = loadTexture(ASSET_TEXTURE_BACKGROUND);
gameTexture = loadTexture(ASSET_TEXTURE_GAMETEXTURES);
carTexture = loadTexture(ASSET_TEXTURE_CAR);
controlTexture = loadTexture(ASSET_TEXTURE_CONTROLTEXTURES);
squirrelWalkDownAnimation = new Animation(0.2f, new TextureRegion(gameTexture, 86, 0, 85, 170), new TextureRegion(gameTexture, 172, 0, 85, 170));
squirrelStandTex = new TextureRegion(gameTexture, 85, 170);
shadowTex = new TextureRegion(gameTexture, 172, 205, 40, 11);
heartTex = new TextureRegion(gameTexture, 172, 171, 37, 33);
heartBlackTex = new TextureRegion(gameTexture, 211, 171, 37, 33);
pineconeBronzeTex = new TextureRegion(gameTexture, 0, 171, 54, 62);
pineconeSilverTex = new TextureRegion(gameTexture, 57, 170, 54, 62);
pineconeGoldTex = new TextureRegion(gameTexture, 115, 171, 54, 62);
points500 = new TextureRegion(gameTexture, 256, 179, 70, 34);
points1000 = new TextureRegion(gameTexture, 328, 179, 90, 34);
points1500 = new TextureRegion(gameTexture, 419, 179, 90, 43);
trafficLightRed = new TextureRegion(gameTexture, 259, 0, 84, 177);
trafficLightYellow = new TextureRegion(gameTexture, 343, 0, 84, 177);
trafficLightGreen = new TextureRegion(gameTexture, 427, 0, 84, 177);
gameOverScreen = new TextureRegion(gameTexture, 21, 249, 231, 231);
pauseScreen = new TextureRegion(gameTexture, 255, 249, 231, 231);
final TextureRegion[][] carFrames = new TextureRegion(carTexture).split(256, 174);
final TextureRegion[][] carFramesFlipped = new TextureRegion(carTexture).split(256, 174);
// flip frames
for (TextureRegion[] frames : carFramesFlipped) {
for (TextureRegion frame : frames) {
frame.flip(true, false);
}
}
carRedDriveLeftAnimation = new Animation(0.1f, carFrames[0][0], carFrames[0][1], carFrames[1][0], carFrames[1][1], carFrames[0][2]);
carRedDriveRightAnimation = new Animation(0.1f, carFramesFlipped[0][0], carFramesFlipped[0][1], carFramesFlipped[1][0], carFramesFlipped[1][1], carFramesFlipped[0][2]);
carCyanDriveLeftAnimation = new Animation(0.1f, carFrames[2][1], carFrames[3][1], carFrames[2][2], carFrames[3][2], carFrames[2][3]);
carCyanDriveRightAnimation = new Animation(0.1f, carFramesFlipped[2][1], carFramesFlipped[3][1], carFramesFlipped[2][2], carFramesFlipped[3][2], carFramesFlipped[2][3]);
carGreenDriveLeftAnimation = new Animation(0.1f, carFrames[1][2], carFrames[0][3], carFrames[1][3], carFrames[2][0], carFrames[3][0]);
carGreenDriveRightAnimation = new Animation(0.1f, carFramesFlipped[1][2], carFramesFlipped[0][3], carFramesFlipped[1][3], carFramesFlipped[2][0], carFramesFlipped[3][0]);
// load fonts
debugFont = new BitmapFont(Gdx.files.internal(ASSET_FONT_DEBUGFONT), false);
scoreFont = new BitmapFont(Gdx.files.internal(ASSET_FONT_SCOREFONT), false);
controlBackgroundTex = new TextureRegionDrawable(new TextureRegion(controlTexture, 176, 176));
controlKnobTex = new TextureRegionDrawable(new TextureRegion(controlTexture, 179, 0, 77, 77));
controlKnobTex.setMinWidth(100);
controlKnobTex.setMinHeight(100);
skin = new Skin();
final TouchpadStyle touchpadStyle = new TouchpadStyle(controlBackgroundTex, controlKnobTex);
skin.add("touchpad", touchpadStyle);
}Example 83
| Project: gdx-ai-master File: PathFinderTests.java View source code |
@Override
public void create() {
Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
// Enable color markup
BitmapFont font = skin.get("default-font", BitmapFont.class);
font.getData().markupEnabled = true;
stage = new Stage();
stage.setDebugAll(DEBUG_STAGE);
stageWidth = stage.getWidth();
stageHeight = stage.getHeight();
Gdx.input.setInputProcessor(new InputMultiplexer(stage));
Stack stack = new Stack();
stage.addActor(stack);
stack.setSize(stageWidth, stageHeight);
testsTable = new Table();
stack.add(testsTable);
// Create behavior selection window
List<String> testList = createTestList();
algorithmSelectionWindow = addBehaviorSelectionWindow("Path Finder Tests", testList, 0, -1);
// Set selected test
changeTest(0);
stage.addActor(new FpsLabel("FPS: ", skin));
}Example 84
| Project: gdx-proto-master File: SmartFontGenerator.java View source code |
/** Will load font from file. If that fails, font will be generated and saved to file. * @param fontFile the actual font (.otf, .ttf) * @param fontName the name of the font, i.e. "arial-small", "arial-large", "monospace-10" * This will be used for creating the font file names * @param fontSize size of font when screen width equals referenceScreenWidth */ public BitmapFont createFont(FileHandle fontFile, String fontName, int fontSize) { BitmapFont font = null; // if fonts are already generated, just load from file Preferences fontPrefs = Gdx.app.getPreferences("org.jrenner.smartfont"); int displayWidth = fontPrefs.getInteger("display-width", 0); int displayHeight = fontPrefs.getInteger("display-height", 0); boolean loaded = false; if (displayWidth != Gdx.graphics.getWidth() || displayHeight != Gdx.graphics.getHeight()) { Gdx.app.debug(TAG, "Screen size change detected, regenerating fonts"); } else { try { // try to load from file Gdx.app.debug(TAG, "Loading generated font from file cache"); font = new BitmapFont(getFontFile(fontName + ".fnt")); loaded = true; } catch (GdxRuntimeException e) { Gdx.app.error(TAG, e.getMessage()); Gdx.app.debug(TAG, "Couldn't load pre-generated fonts. Will generate fonts."); } } if (!loaded || forceGeneration) { forceGeneration = false; float width = Gdx.graphics.getWidth(); // use 1920x1280 as baseline, arbitrary float ratio = width / referenceScreenWidth; // for 28 sized fonts at baseline width above float baseSize = 28f; // store screen width for detecting screen size change // on later startups, which will require font regeneration fontPrefs.putInteger("display-width", Gdx.graphics.getWidth()); fontPrefs.putInteger("display-height", Gdx.graphics.getHeight()); fontPrefs.flush(); font = generateFontWriteFiles(fontName, fontFile, fontSize, pageSize, pageSize); } return font; }
Example 85
| Project: gdx-skineditor-master File: NewFontDialog.java View source code |
@Override
public void changed(ChangeEvent event, Actor actor) {
// First check if the name is already in use
if (game.skinProject.has(textFontName.getText(), BitmapFont.class)) {
game.showNotice("Error", "A font with the same name already exists!", getStage());
return;
}
String properFontName = generateProperFontName(selectFonts.getSelected());
FileHandle handleFont = new FileHandle(System.getProperty("java.io.tmpdir")).child(properFontName + ".fnt");
FileHandle handleImage = new FileHandle(System.getProperty("java.io.tmpdir")).child(properFontName + ".png");
FileHandle targetFont = Gdx.files.local("projects/" + game.screenMain.getcurrentProject() + "/" + textFontName.getText() + ".fnt");
FileHandle targetImage = Gdx.files.local("projects/" + game.screenMain.getcurrentProject() + "/assets/" + textFontName.getText() + ".png");
if ((targetFont.exists() == true) || (targetImage.exists() == true)) {
game.showNotice("Error", "A file with the same name already exists!", getStage());
return;
}
handleFont.copyTo(targetFont);
handleImage.copyTo(targetImage);
game.skinProject.add(textFontName.getText(), new BitmapFont(targetFont, targetImage, false));
game.screenMain.saveToSkin();
game.screenMain.refreshResources();
hide();
}Example 86
| Project: GdxDemo3D-master File: NavMeshDebugDrawer.java View source code |
private void drawNavMeshIndices(SpriteBatch spriteBatch, Camera camera, BitmapFont font) {
// TODO: Get rid of all the transform matrix setting
if (spriteBatch.isDrawing()) {
spriteBatch.end();
}
spriteBatch.begin();
spriteBatch.setProjectionMatrix(camera.combined);
for (int i = 0; i < navMesh.graph.getNodeCount(); i++) {
Triangle t = navMesh.graph.getTriangleFromGraphIndex(i);
if (triangleIsVisible(t)) {
tmpMatrix.set(camera.view).inv().getRotation(tmpQuat);
tmpMatrix.setToTranslation(t.centroid).rotate(tmpQuat);
spriteBatch.setTransformMatrix(tmpMatrix);
font.draw(spriteBatch, Integer.toString(t.triIndex), 0, 0);
}
}
spriteBatch.end();
}Example 87
| Project: GdxStudio-master File: ParticleRenderer.java View source code |
@Override
public void create() {
if (spriteBatch != null)
return;
Texture.setEnforcePotImages(false);
spriteBatch = new SpriteBatch();
this.particlePanel.worldCamera = new OrthographicCamera();
this.particlePanel.textCamera = new OrthographicCamera();
this.particlePanel.pixelsPerMeter = new NumericValue();
this.particlePanel.pixelsPerMeter.setValue(1.0f);
this.particlePanel.pixelsPerMeter.setAlwaysActive(true);
this.particlePanel.zoomLevel = new NumericValue();
this.particlePanel.zoomLevel.setValue(1.0f);
this.particlePanel.zoomLevel.setAlwaysActive(true);
this.particlePanel.deltaMultiplier = new NumericValue();
this.particlePanel.deltaMultiplier.setValue(1.0f);
this.particlePanel.deltaMultiplier.setAlwaysActive(true);
font = new BitmapFont(Gdx.files.getFileHandle("default.fnt", FileType.Internal), Gdx.files.getFileHandle("default.png", FileType.Internal), true);
this.particlePanel.effectPanel.newExampleEmitter("Untitled", true);
// if (resources.openFile("/editor-bg.png") != null) bgImage = new Image(gl, "/editor-bg.png");
//Gdx.input.setInputProcessor(this);
}Example 88
| Project: overlap2d-runtime-libgdx-master File: LabelSystem.java View source code |
@Override
protected void processEntity(Entity entity, float deltaTime) {
transformComponent = transformComponentMapper.get(entity);
labelComponent = labelComponentMapper.get(entity);
dimensionsComponent = dimensionComponentMapper.get(entity);
BitmapFont font = labelComponent.cache.getFont();
float oldScaleX = font.getScaleX();
float oldScaleY = font.getScaleY();
float fontScaleX = labelComponent.fontScaleX;
float fontScaleY = labelComponent.fontScaleY;
if (fontScaleX != 1 || fontScaleY != 1)
font.getData().setScale(fontScaleX, fontScaleY);
//horisontal Align
float textWidth = labelComponent.layout.width;
float textHeight = labelComponent.layout.height;
float textX = 0;
if (labelComponent.wrap || labelComponent.text.indexOf("\n") != -1) {
// If the text can span multiple lines, determine the text's actual size so it can be aligned within the label.
labelComponent.layout.setText(font, labelComponent.text, 0, labelComponent.text.length, Color.WHITE, dimensionsComponent.width, labelComponent.lineAlign, labelComponent.wrap, null);
textWidth = labelComponent.layout.width;
textHeight = labelComponent.layout.height;
if ((labelComponent.lineAlign & Align.left) == 0) {
if ((labelComponent.lineAlign & Align.right) != 0)
textX += dimensionsComponent.width - textWidth;
else
textX += (dimensionsComponent.width - textWidth) / 2;
}
}
//vertical Align
float textY = textHeight;
if ((labelComponent.labelAlign & Align.top) != 0) {
textY += labelComponent.cache.getFont().isFlipped() ? 0 : dimensionsComponent.height - textHeight;
textY += labelComponent.style.font.getDescent();
} else if ((labelComponent.labelAlign & Align.bottom) != 0) {
textY += labelComponent.cache.getFont().isFlipped() ? dimensionsComponent.height - textHeight : 0;
textY -= labelComponent.style.font.getDescent();
} else {
textY += (dimensionsComponent.height - textHeight) / 2;
}
labelComponent.layout.setText(font, labelComponent.text, 0, labelComponent.text.length, Color.WHITE, dimensionsComponent.width, labelComponent.lineAlign, labelComponent.wrap, null);
labelComponent.cache.setText(labelComponent.layout, textX, textY);
if (fontScaleX != 1 || fontScaleY != 1)
font.getData().setScale(oldScaleX, oldScaleY);
}Example 89
| Project: pax-master File: Help.java View source code |
@Override
public void show() {
GameInstance.getInstance().resetGame();
blackFade = Resources.getInstance().blackFade;
back = Resources.getInstance().back;
back.setPosition(20, 010);
back.setColor(1, 1, 1, 0.5f);
collisionBack.set(new Vector3(back.getVertices()[0], back.getVertices()[1], -10), new Vector3(back.getVertices()[10], back.getVertices()[11], 10));
fighter = Resources.getInstance().fighterOutline;
fighter.setRotation(0);
bomber = Resources.getInstance().bomberOutline;
bomber.setRotation(0);
frigate = Resources.getInstance().frigateOutline;
frigate.setRotation(0);
upgrade = Resources.getInstance().upgradeOutline;
upgrade.setRotation(0);
titleBatch = new SpriteBatch();
titleBatch.getProjectionMatrix().setToOrtho2D(0, 0, 800, 480);
fadeBatch = new SpriteBatch();
fadeBatch.getProjectionMatrix().setToOrtho2D(0, 0, 2, 2);
font = new BitmapFont();
font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
}Example 90
| Project: runpogsrun-master File: ResourceManager.java View source code |
public boolean load() {
BitmapFont font = new BitmapFont(Gdx.files.internal(fntFile), Gdx.files.internal(pngFile), false);
if (font != null) {
fonts.put(name, font);
disposables.add(font);
if (isDebug) {
L.wtf(name + " Succesfully Loaded..");
}
}
return font != null ? true : false;
}Example 91
| Project: SIFTrain-master File: Assets.java View source code |
// In here we'll put everything that needs to be loaded in this format:
// manager.load("file location in assets", fileType.class);
//
// libGDX AssetManager currently supports: Pixmap, Texture, BitmapFont,
// TextureAtlas, TiledAtlas, TiledMapRenderer, Music and Sound.
public static void queueLoading() {
internalManager.load("textures/textures.pack.atlas", TextureAtlas.class);
internalManager.load("hitsounds/bad.mp3", Sound.class);
internalManager.load("hitsounds/good.mp3", Sound.class);
internalManager.load("hitsounds/great.mp3", Sound.class);
internalManager.load("hitsounds/perfect.mp3", Sound.class);
internalManager.load("bigimages/main_menu_background.jpg", Texture.class);
internalManager.load("images/hold_background.png", Texture.class);
internalManager.load("fonts/combo-font.fnt", BitmapFont.class);
internalManager.load("fonts/song-font.fnt", BitmapFont.class);
reloadBeatmaps();
}Example 92
| Project: snappyfrog-master File: Game.java View source code |
@SuppressWarnings("deprecation")
@Override
public void create() {
singleton = this;
platformServices.initGamePadControllers();
// Get width, height
Game.width = Gdx.graphics.getWidth();
Game.height = Gdx.graphics.getHeight();
GRAVITY = ResHelper.LinearHeightValue(1000.0f);
randomGenerator = new Random(TimeUtils.millis());
// Init objects
textureAtlas = new TextureAtlas(Gdx.files.internal("textures/pack.atlas"));
skin = new Skin();
skin.addRegions(textureAtlas);
if (platformServices.supportsFreetype()) {
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("slkscr.ttf"));
buttonFont = generator.generateFont((int) ResHelper.LinearHeightValue(18));
scoreFont = generator.generateFont((int) ResHelper.LinearHeightValue(14));
hintFont = generator.generateFont((int) ResHelper.LinearHeightValue(12));
generator.dispose();
} else {
buttonFont = new BitmapFont(Gdx.files.internal("prerenderedFonts/buttonFont.fnt"));
scoreFont = new BitmapFont(Gdx.files.internal("prerenderedFonts/scoreFont.fnt"));
hintFont = new BitmapFont(Gdx.files.internal("prerenderedFonts/hintFont.fnt"));
}
plusOneSound = Gdx.audio.newSound(Gdx.files.internal("sounds/plusOne.wav"));
crashSound = Gdx.audio.newSound(Gdx.files.internal("sounds/crash.wav"));
bigJumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/bigJump.wav"));
smallJumpSound = Gdx.audio.newSound(Gdx.files.internal("sounds/smallJump.wav"));
newRecordSound = Gdx.audio.newSound(Gdx.files.internal("sounds/newRecord.wav"));
cheerSound = Gdx.audio.newSound(Gdx.files.internal("sounds/cheer.wav"));
gaspSound = Gdx.audio.newSound(Gdx.files.internal("sounds/gasp.wav"));
laserSound = Gdx.audio.newSound(Gdx.files.internal("sounds/laser.wav"));
goldMedal = textureAtlas.createSprite("misc/medal-gold");
missMedal = textureAtlas.createSprite("misc/medal-miss");
preferences = Gdx.app.getPreferences("Globals");
if (!preferences.contains("highscore"))
preferences.putInteger("highscore", 0);
if (!preferences.contains("tutorial"))
preferences.putBoolean("tutorial", true);
if (!preferences.contains("secret_column"))
preferences.putInteger("secret_column", 5 + randomGenerator.nextInt(25));
if (!preferences.contains("user_shared"))
preferences.putBoolean("user_shared", false);
preferences.flush();
setScreen(new LevelScreen(true));
}Example 93
| Project: SquidLib-master File: FontTest.java View source code |
@Override
public void create() {
batch = new SpriteBatch();
//widths = new int[]{100, 95, 90, 110, 95, 50, 125, 170, 200, 90};
//heights = new int[]{20, 21, 20, 28, 18, 20, 22, 25, 25, 25};
widths = new int[] { 100, 95, 90, 110, 120, 50, 125, 170, 200, 220 };
heights = new int[] { 20, 21, 20, 28, 22, 20, 22, 25, 25, 25 };
factories = new TextCellFactory[] { DefaultResources.getStretchableFont().width(13).height(30).initBySize(), DefaultResources.getStretchableTypewriterFont().width(14).height(28).initBySize(), DefaultResources.getStretchableCodeFont().width(15).height(27).initBySize(), DefaultResources.getStretchableDejaVuFont().width(14).height(25).initBySize(), //DefaultResources.getStretchableSciFiFont().width(28).height(64).initBySize(),
DefaultResources.getStretchableSlabFont().width(11).height(20).initBySize(), DefaultResources.getStretchableSquareFont().width(20).height(20).initBySize(), DefaultResources.getStretchableLeanFont().width(11).height(20).initBySize(), DefaultResources.getStretchableOrbitFont().initBySize(), DefaultResources.getStretchablePrintFont().initBySize(), DefaultResources.getStretchableCleanFont().initBySize() };
viewports = new Viewport[] { new StretchViewport(factories[0].width() * widths[0], factories[0].height() * heights[0]), new StretchViewport(factories[1].width() * widths[2], factories[1].height() * heights[1]), new StretchViewport(factories[2].width() * widths[2], factories[2].height() * heights[2]), new StretchViewport(factories[3].width() * widths[3], factories[3].height() * heights[3]), new StretchViewport(factories[4].width() * widths[4], factories[4].height() * heights[4]), new StretchViewport(factories[5].width() * widths[5], factories[5].height() * heights[5]), new StretchViewport(factories[6].width() * widths[6], factories[6].height() * heights[6]), new StretchViewport(factories[7].width() * widths[7], factories[7].height() * heights[7]), new StretchViewport(factories[8].width() * widths[8], factories[8].height() * heights[8]), new StretchViewport(factories[9].width() * widths[9], factories[9].height() * heights[9]) };
displays = new SquidPanel[] { new SquidPanel(widths[0], heights[0], factories[0]).setTextSize(factories[0].width() + 0, factories[0].height() + 0), new SquidPanel(widths[2], heights[1], factories[1]).setTextSize(factories[1].width() + 1, factories[1].height() + 2), new SquidPanel(widths[2], heights[2], factories[2]).setTextSize(factories[2].width() + 3, factories[2].height() + 4), new SquidPanel(widths[3], heights[3], factories[3]).setTextSize(factories[3].width() + 1, factories[3].height() + 2), new SquidPanel(widths[4], heights[4], factories[4]).setTextSize(factories[4].width() + 1, factories[4].height() + 2), new SquidPanel(widths[5], heights[5], factories[5]).setTextSize(factories[5].width() + 0, factories[5].height() + 0), new SquidPanel(widths[6], heights[6], factories[6]).setTextSize(factories[6].width() + 2, factories[6].height() + 2), new SquidPanel(widths[7], heights[7], factories[7]).setTextSize(factories[7].width() + 1, factories[7].height() + 2), new SquidPanel(widths[8], heights[8], factories[8]).setTextSize(factories[8].width() + 1, factories[8].height() + 2), new SquidPanel(widths[9], heights[9], factories[9]).setTextSize(factories[9].width() + 1, factories[9].height() + 2) };
final String[] samples = { "The quick brown fox jumps over the lazy dog.", "HAMBURGEVONS", "Black Sphinx Of Quartz: Judge Ye My Vow!" };
texts = new ArrayList<>(4);
text = new TextPanel<Color>(null, factories[7]);
text.init(totalWidth, totalHeight, Color.WHITE, samples);
texts.add(text);
text = new TextPanel<Color>(null, factories[8]);
text.init(totalWidth, totalHeight, Color.WHITE, samples);
texts.add(text);
text = new TextPanel<Color>(null, factories[9]);
text.init(totalWidth, totalHeight, Color.WHITE, samples);
texts.add(text);
for (int i = 0; i < factories.length; i++) {
tcf = factories[i];
display = displays[i];
BitmapFont.BitmapFontData data = tcf.font().getData();
int p = 0, x = 0, y = 0;
BitmapFont.Glyph[] glyphs;
BitmapFont.Glyph g;
ALL_PAGES: while (p < data.glyphs.length) {
glyphs = data.glyphs[p++];
if (glyphs == null)
continue;
int gl = glyphs.length;
for (int gi = 0; gi < gl; gi++) {
if ((g = glyphs[gi]) != null) {
display.put(x++, y, (char) g.id);
if (x >= widths[i]) {
x = 0;
if (++y >= heights[i]) {
break ALL_PAGES;
}
}
}
}
}
}
tcf = factories[index];
display = displays[index];
viewport = viewports[index];
cellWidth = tcf.width();
cellHeight = tcf.height();
stage = new Stage(viewport, batch);
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean keyUp(int keycode) {
index = ((index + 1) % 10);
viewport = viewports[index];
if (index < 7) {
tcf = factories[index];
display = displays[index];
stage.clear();
stage.setViewport(viewport);
stage.addActor(display);
} else {
text = texts.get(index - 7);
stage.clear();
stage.setViewport(viewport);
stage.addActor(text.getScrollPane());
}
Gdx.graphics.setTitle("SquidLib Demo: Fonts, preview " + (index + 1) + "/" + viewports.length + " (press any key)");
return true;
}
});
Gdx.graphics.setTitle("SquidLib Demo: Fonts, preview " + (index + 1) + "/" + viewports.length + " (press any key)");
stage.addActor(display);
}Example 94
| Project: SUPERULTIMATEOTHELLO-master File: GameMain.java View source code |
@Override
public void create() {
prefs = Gdx.app.getPreferences("Preferences");
InputMultiplexer multiplexer = new InputMultiplexer();
UIButtonListener uiButtonListener = new UIButtonListener();
screenHeight = Gdx.graphics.getHeight();
screenWidth = Gdx.graphics.getWidth();
if (screenHeight >= screenWidth) {
scale = (screenWidth / 8);
} else {
scale = (screenHeight / 8);
}
apple = new ShapeRenderer();
myController = new MyController(8, scale);
teams = myController.getPiecesTeams();
//////
stage = new Stage();
skin = new Skin();
// Generate a 1x1 white texture and store it in the skin named "white".
Pixmap pixmap = new Pixmap((int) scale, (int) scale, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
// Store the default libgdx font under the name "default".
skin.add("default", new BitmapFont());
// Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
BitmapFont font = new BitmapFont();
font.setScale(1);
textButtonStyle.font = font;
skin.add("default", textButtonStyle);
final TextButton button = new TextButton("Reset Board", skin);
uiButtonListener.setButton(button);
final TextButton saveAndQuitButton = new TextButton("Save and Quit", skin);
uiButtonListener.setSaveAndQuitButton(saveAndQuitButton);
cantUndoButton = new TextButton("Cannot undo previous move", skin);
undoButton = new TextButton("Undo Last Move", skin);
uiButtonListener.setUndoButton(undoButton);
button.addListener(uiButtonListener);
saveAndQuitButton.addListener(uiButtonListener);
undoButton.addListener(uiButtonListener);
// label
LabelStyle labelStyle = new LabelStyle(font, Color.GREEN);
statusLabel = new Label("", labelStyle);
stack = new Stack();
stack.add(cantUndoButton);
stack.add(undoButton);
Table table = new Table();
table.add(stack).height((scale * 1.5f)).expandY().padTop((scale * .5f)).prefWidth((screenWidth - screenHeight) - scale);
table.row();
table.add(button).height((scale * 1.5f)).expandY().padBottom((scale * .5f)).padTop((scale * .5f)).prefWidth((screenWidth - screenHeight) - scale);
table.row();
table.add(saveAndQuitButton).height((scale * 1.5f)).expandY().padBottom((scale * .5f)).prefWidth((screenWidth - screenHeight) - scale);
table.row();
table.add(statusLabel).height((scale * 1.5f)).expandY().padBottom((scale * .5f)).prefWidth((screenWidth - screenHeight) - scale);
table.setFillParent(false);
table.setVisible(true);
table.setSize((screenWidth - screenHeight), screenHeight);
table.setPosition(screenHeight, 0);
stage.addActor(table);
multiplexer.addProcessor(myController);
multiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(multiplexer);
String savedBoardJsonString = prefs.getString(PREFS_BOARD_KEY, null);
int savedTurn = prefs.getInteger(PREFS_PLAYER_TURN);
if (savedBoardJsonString != null) {
myController.setBoard(savedBoardJsonString);
myController.setTurn(savedTurn);
}
}Example 95
| Project: TDT4240_Project_Source-master File: Shop.java View source code |
public void update() {
font = new BitmapFont();
weaponCost = Game.getInstance().getGui().getWeaponCost();
hullCost = Game.getInstance().getGui().getHullCost();
shieldCost = Game.getInstance().getGui().getShieldCost();
speedCost = Game.getInstance().getGui().getSpeedCost();
weaponString = Game.getInstance().getGui().getWeaponString();
if (weaponStringNew == null)
weaponStringNew = Game.getInstance().getGui().getWeaponString();
hullString = Game.getInstance().getGui().getHullString();
if (hullStringNew == null)
hullStringNew = Game.getInstance().getGui().getHullString();
shieldString = Game.getInstance().getGui().getShieldString();
if (shieldStringNew == null)
shieldStringNew = Game.getInstance().getGui().getShieldString();
speedString = Game.getInstance().getGui().getSpeedString();
if (speedStringNew == null)
speedStringNew = Game.getInstance().getGui().getSpeedString();
if (Game.getInstance().getInput().isWeaponUpgraded() && Game.getInstance().getPlayer().getScore() >= weaponUpgradeCost) {
weaponUpgrade++;
if (weaponUpgrade == 1)
weaponUpgradeCostOrig = weaponUpgradeCost;
Game.getInstance().getPlayer().setScore(Game.getInstance().getPlayer().getScore() - weaponUpgradeCost);
weaponUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getWeaponLevel() + weaponUpgrade - 1);
float x = weaponCost.getX();
float y = weaponCost.getY();
weaponStringNew = "Current weapon level: " + (Game.getInstance().getPlayer().getWeaponLevel() + weaponUpgrade) + "\n" + "Upgrade cost: " + weaponUpgradeCost;
weaponCost.setMultiLineText(weaponStringNew, 0, 0);
weaponCost.setPosition(x, y);
}
if (Game.getInstance().getInput().isHullUpgraded() && Game.getInstance().getPlayer().getScore() >= hullUpgradeCost) {
hullUpgrade++;
if (hullUpgrade == 1)
hullUpgradeCostOrig = hullUpgradeCost;
Game.getInstance().getPlayer().setScore(Game.getInstance().getPlayer().getScore() - hullUpgradeCost);
hullUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getHullLevel() + hullUpgrade);
float x = hullCost.getX();
float y = hullCost.getY();
hullUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getHullLevel() + hullUpgrade);
hullStringNew = "Current hull level: " + (Game.getInstance().getPlayer().getHullLevel() + hullUpgrade) + "\n" + "Upgrade cost: " + hullUpgradeCost;
hullCost.setMultiLineText(hullStringNew, 0, 0);
hullCost.setPosition(x, y);
}
if (Game.getInstance().getInput().isShieldUpgraded() && Game.getInstance().getPlayer().getScore() >= shieldUpgradeCost) {
shieldUpgrade++;
if (shieldUpgrade == 1)
shieldUpgradeCostOrig = shieldUpgradeCost;
Game.getInstance().getPlayer().setScore(Game.getInstance().getPlayer().getScore() - shieldUpgradeCost);
shieldUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getShieldLevel() + shieldUpgrade);
float x = shieldCost.getX();
float y = shieldCost.getY();
shieldUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getShieldLevel() + shieldUpgrade);
shieldStringNew = "Current shield level: " + (Game.getInstance().getPlayer().getShieldLevel() + shieldUpgrade) + "\n" + "Upgrade cost: " + shieldUpgradeCost;
shieldCost.setMultiLineText(shieldStringNew, 0, 0);
shieldCost.setPosition(x, y);
}
if (Game.getInstance().getInput().isSpeedUpgraded() && Game.getInstance().getPlayer().getScore() >= speedUpgradeCost) {
speedUpgrade++;
if (speedUpgrade == 1)
speedUpgradeCostOrig = speedUpgradeCost;
Game.getInstance().getPlayer().setScore(Game.getInstance().getPlayer().getScore() - speedUpgradeCost);
speedUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getSpeedLevel() + speedUpgrade);
float x = speedCost.getX();
float y = speedCost.getY();
speedUpgradeCost = 5000 + 5000 * (Game.getInstance().getPlayer().getSpeedLevel() + speedUpgrade);
speedStringNew = "Current speed level: " + (Game.getInstance().getPlayer().getSpeedLevel() + speedUpgrade) + "\n" + "Upgrade cost: " + speedUpgradeCost;
speedCost.setMultiLineText(speedStringNew, 0, 0);
speedCost.setPosition(x, y);
}
if (Game.getInstance().getInput().isConfirmUpgrades()) {
upgradeEquipment();
resetUpgrades();
isActive = false;
}
if (Game.getInstance().getInput().isCancelUpgrades()) {
resetEquipment();
resetUpgrades();
}
// Maybe smarter way to do this so it does not setRegion every update
if (Game.getInstance().getInput().isWeaponPressed()) {
Game.getInstance().getGui().setWeaponTexture(Game.getInstance().getGui().getTextureUpgWeaponPressed());
} else {
Game.getInstance().getGui().setWeaponTexture(Game.getInstance().getGui().getTextureUpgWeapon());
}
if (Game.getInstance().getInput().isHullPressed()) {
Game.getInstance().getGui().setHullTexture(Game.getInstance().getGui().getTextureUpgHullPressed());
} else {
Game.getInstance().getGui().setHullTexture(Game.getInstance().getGui().getTextureUpgHull());
}
if (Game.getInstance().getInput().isShieldPressed()) {
Game.getInstance().getGui().setShieldTexture(Game.getInstance().getGui().getTextureUpgShieldPressed());
} else {
Game.getInstance().getGui().setShieldTexture(Game.getInstance().getGui().getTextureUpgShield());
}
if (Game.getInstance().getInput().isSpeedPressed()) {
Game.getInstance().getGui().setSpeedTexture(Game.getInstance().getGui().getTextureUpgSpeedPressed());
} else {
Game.getInstance().getGui().setSpeedTexture(Game.getInstance().getGui().getTextureUpgSpeed());
}
if (Game.getInstance().getInput().isResetPressed()) {
Game.getInstance().getGui().setResetTexture(Game.getInstance().getGui().getTextureResetPressed());
} else {
Game.getInstance().getGui().setResetTexture(Game.getInstance().getGui().getTextureReset());
}
}Example 96
| Project: umbracraft-master File: MessageWindowLayout.java View source code |
@Override
public void show() {
Table windowFrame = new Table() {
{
add(nameTable = new Table() {
{
setBackground(Drawables.ninePatch("ui/namePlate"));
add(nameLabel = new VisLabel("Amiru", new LabelStyle(Game.assets().get("fonts/message.fnt", BitmapFont.class), Color.WHITE))).pad(0, 60, 18, 20);
}
}).height(20).expand().bottom().left().row();
add(messageWindow = new WindowTable(messageStyle) {
{
getColor().a = 0;
put(messageTextTable());
}
}).expand().fillX().bottom().padBottom(10);
}
};
//= width of face
content.add(faceTable = new Table()).bottom().width(0).padRight(-FACE_WIDTH);
content.add(windowFrame).expand().bottom();
faceTable.toFront();
// do actions
messageWindow.addAction(Actions.sequence(Actions.alpha(0), Actions.moveBy(0, -10), Actions.parallel(Actions.moveBy(0, 10, SHOW_TRANSITION_TIME, Interpolation.pow2Out), Actions.alpha(1, SHOW_TRANSITION_TIME)), Actions.run(new Runnable() {
@Override
public void run() {
state = MessageState.STEP_2_ACCEPT_INPUT;
}
})));
messageTable.addAction(Actions.sequence(Actions.alpha(0), Actions.delay(0.3f), Actions.alpha(1, SHOW_TRANSITION_TIME)));
}Example 97
| Project: zxzx-master File: Assets.java View source code |
private static void loadFonts() {
String fontDir = "fonts/";
scoreFont = new BitmapFont(Gdx.files.internal(fontDir + SCORE_FONT), false);
textFont = new BitmapFont(Gdx.files.internal(fontDir + TEXT_FONT), false);
flyupFont = new BitmapFont(Gdx.files.internal(fontDir + FLYUP_FONT), false);
scoreFont.setScale(1.0f);
textFont.setScale(1.0f);
flyupFont.setScale(1.0f);
}Example 98
| Project: alienchase-master File: GameplayScreen.java View source code |
@Override
public void show() {
if (sonidoFondo) {
AlienChase.MANAGER.get("sound/corazon.ogg", Sound.class).loop();
}
// Creamos un nuevo escenario y lo asociamos a la entrada.
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
stage = new Stage(width, height, true, game.SB);
Gdx.input.setInputProcessor(stage);
// Crear fondo.
Image imgFondo = new Image(AlienChase.MANAGER.get("images/fondo.png", Texture.class));
imgFondo.setFillParent(true);
stage.addActor(imgFondo);
// Creamos una nave.
nave = new NaveActor(stage);
nave.setPosition(stage.getWidth() / 2 - nave.getHeight() / 2, 10);
// Creamos los HUD de las naves.
vidaNave = new BarraActor(stage, nave);
vidaNave.setPosition(stage.getWidth() - 150, stage.getHeight() - 20);
// Creamos la puntuación.
puntuacion = new PuntuacionActor(stage, new BitmapFont(), nave);
puntuacion.setPosition(10, stage.getHeight() - 10);
// Creamos los escudos.
crearEscudos();
// Creamos los aliens.
crearAliens();
// Preparamos los listeners
crearListeners();
state = State.RUNNING;
}Example 99
| Project: Drona-The-Dragon-Saviour-master File: Assets.java View source code |
private static void loadFonts() {
// Load the fonts
gameFont = new BitmapFont(Gdx.files.internal("data/gamefont.fnt"), Gdx.files.internal("data/gamefont.png"), false);
whiteFont = new BitmapFont(Gdx.files.internal("data/whiteFont.fnt"), Gdx.files.internal("data/whiteFont.png"), false);
smallFont = new BitmapFont(Gdx.files.internal("data/smallFont.fnt"), Gdx.files.internal("data/smallFont.png"), false);
}Example 100
| Project: Escape-of-the-Ninja-master File: GameScreen.java View source code |
@Override
public void show() {
stage.addActor(new Background());
stage.addActor(borderGroup);
stage.addActor(playerActor);
camera = new OrthographicCamera();
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();
camera.setToOrtho(false, w, h);
batch = new SpriteBatch();
tapToStart = new Image(new Texture(Gdx.files.internal("title.png")));
lostImage = new Image(new Texture(Gdx.files.internal("youlost.png")));
bg = new Texture(Gdx.files.internal("earth.png"));
lostImage.setVisible(false);
stage.addActor(tapToStart);
stage.addActor(lostImage);
stage.addActor(hud);
music.setLooping(true);
//music.play();
LabelStyle style = new LabelStyle(new BitmapFont(), Color.WHITE);
highscoreImage = new Image(new Texture(Gdx.files.internal("highscore.png")));
highscoreImage.setX(w / 2 - highscoreImage.getWidth() / 2);
highscoreImage.setY(h - highscoreImage.getHeight() * 2);
highscoreImage.setOrigin(highscoreImage.getWidth() / 2, highscoreImage.getHeight() / 2);
highscoreImage.addAction(Actions.alpha(0));
stage.addActor(highscoreImage);
Gdx.input.setInputProcessor(stage);
}Example 101
| Project: keyflection-gdx-master File: DemoUI.java View source code |
@Override
public void create() {
background = new Color(0.2f, 0.2f, 0.2f, 1f);
texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false);
stageActions = new StageKeys();
stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
float loc = (NUM_SPRITES * (32 + SPACING) - SPACING) / 2;
for (int i = 0; i < NUM_GROUPS; i++) {
Group group = new Group();
group.setX((float) Math.random() * (stage.getWidth() - NUM_SPRITES * (32 + SPACING)));
group.setY((float) Math.random() * (stage.getHeight() - NUM_SPRITES * (32 + SPACING)));
group.setOrigin(loc, loc);
fillGroup(group, texture);
stage.addActor(group);
}
uiTexture = new Texture(Gdx.files.internal("data/ui.png"));
uiTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
ui = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
ui.addListener(new KeyflectionInputListener(stageActions));
Image blend = new Image(new TextureRegion(uiTexture, 0, 0, 64, 32));
blend.setAlign(Align.center);
blend.setScaling(Scaling.none);
blend.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
stageActions.toggleBlending();
return true;
}
});
blend.setY(ui.getHeight() - 64);
Image rotate = new Image(new TextureRegion(uiTexture, 64, 0, 64, 32));
rotate.setAlign(Align.center);
rotate.setScaling(Scaling.none);
rotate.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
stageActions.toggleRotation();
return true;
}
});
rotate.setPosition(64, blend.getY());
Image scale = new Image(new TextureRegion(uiTexture, 64, 32, 64, 32));
scale.setAlign(Align.center);
scale.setScaling(Scaling.none);
scale.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
stageActions.toggleScaling();
return true;
}
});
scale.setPosition(128, blend.getY());
ui.addActor(blend);
ui.addActor(rotate);
ui.addActor(scale);
hint = new Label("Press F1 to see keyboard shortcuts.", new Label.LabelStyle(font, Color.WHITE));
hint.setPosition(10, 45);
hint.setColor(0, 1, 0, 1);
ui.addActor(hint);
fps = new Label("fps: 0", new Label.LabelStyle(font, Color.WHITE));
fps.setPosition(10, 30);
fps.setColor(0, 1, 0, 1);
ui.addActor(fps);
renderer = new ShapeRenderer();
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(new KeyflectionInputProcessor(new GlobalKeys()));
multiplexer.addProcessor(stage);
multiplexer.addProcessor(ui);
Gdx.input.setInputProcessor(multiplexer);
}