public void update(float delta) { Entity playerEntity = player.get(0); PlayerSteerableComponent psc = cmpsc.get(playerEntity); for (int i = 0; i < entities.size(); i++) { Entity entity = entities.get(i); TalkComponent tc = cmtc.get(entity); NonControllablePersonSteerableComponent ncpstc = cmstc.get(entity); if (ncpstc.x - 160 < psc.getPosition().x && psc.getPosition().x < ncpstc.x + 160 && ncpstc.y - 210 < psc.getPosition().y && psc.getPosition().y < ncpstc.y + 210) { layout.setText(font, tc.textToSay); float x = ncpstc.x - (layout.width / 2); float y = ncpstc.y + layout.height + 15; batch.end(); shapeRenderer.setProjectionMatrix(TwoD.getMain().camera.combined); shapeRenderer.begin(ShapeType.Filled); shapeRenderer.setColor(Color.WHITE); shapeRenderer.rect(x - 13, y + 2, 26 + layout.width, 26 + layout.height); shapeRenderer.setColor(Color.BLACK); shapeRenderer.rect(x - 10, y + 5, 20 + layout.width, 20 + layout.height); shapeRenderer.end(); batch.begin(); font.draw(batch, layout, x, y + 25); } } }
public void drawFont(String text, int x, int y, boolean center) { layout.setText(font, text); float w = layout.width; float h = layout.height; if (center) { font.draw(batch, text, x - w / 2, y - h / 2); } else font.draw(batch, text, x, y); }
// Metodo que acomoda el texto al centro y arriba de la pantalla private void SetFontTextCenter(TitleActor fontActor, String text) { imageTitle.ChangeFontText(titlesList.get(0)); GlyphLayout layout = new GlyphLayout(); layout.setText(fontActor.GetFont(), text); float textX = (Gdx.graphics.getWidth() / 2) - (layout.width / 2); float textY = layout.height + (Gdx.graphics.getHeight() - 50f); fontActor.setPosition(textX, textY); }
/** * Helper function to actually render the text. * * @param batch the spritebatch to use. * @param message The string to add. * @param x The x location. * @param y The y location. * @param color The colour to render the text as. * @param font The font to use. */ private void renderText( SpriteBatch batch, String message, float x, float y, Color color, BitmapFont font) { GlyphLayout layout = new GlyphLayout(font, message, Color.BLACK, width - paddingX * 2, Align.left, false); font.draw(batch, layout, x + paddingX, y + height + paddingY - 2); layout.setText(font, message, color, width - paddingX * 2, Align.left, false); font.draw(batch, layout, x + paddingX, y + height + paddingY); }
public void resetGoldValue() { playerGoldValueGlyph.setText( StaticBitmapFont.getBitmapFont(), "" + FastClicker.getMoney(), Color.YELLOW, 0, Align.left, false); goldNumberX = (int) ((FastClicker.WIDTH - playerGoldValueGlyph.width) / 2); }
public static void drawCenteredText( SpriteBatch batch, Color color, String text, float x, float y, float scale) { final BitmapFont font = getFont(); font.getData().setScale(scale); layout.setText(font, text); final float textWidth = layout.width; final float left = x - (textWidth / 2); final float textHeight = font.getLineHeight(); font.setColor(color); font.draw(batch, text, left, y + (textHeight / 2)); }
protected void computeInitialGlyphLayout(@NtN Vector2 size) { glyphLayout.setText(font, rawText, Color.BLACK, size.x, Align.left, true); StringBuilder text = new StringBuilder(); float minY = 0, maxY = 0; for (GlyphLayout.GlyphRun run : glyphLayout.runs) { minY = Math.min(run.y, minY); maxY = Math.max(run.y, maxY); for (BitmapFont.Glyph glyph : run.glyphs) text.append(glyph.toString()); } computedText = text.toString(); futureRuns = new Array<>(glyphLayout.runs); futureRuns.reverse(); glyphLayout.runs.clear(); }
public void drawString(String s, float x, float y, float fontSize, boolean centered, Color col) { if (s == null) return; myTextureChecker.onString(myFont.getRegion().getTexture()); myFont.setColor(col); myFont.getData().setScale(fontSize / myOrigFontHeight); if (!centered) { myFont.draw(mySpriteBatch, s, x, y); return; } // http://www.badlogicgames.com/wordpress/?p=3658 layout.reset(); layout.setText(myFont, s); x -= layout.width / 2; y -= layout.height / 2; myFont.draw(mySpriteBatch, layout, x, y); }
private void drawEnemyState(SpriteBatch batch) { for (Enemy enemy : GameController.getInstance().getEnemiesMap().values()) { IEnemyState state = GdxController.getInstance().getEnemyGdx().getStateMap().get(enemy.getId()); GlyphLayout glyphLayout = new GlyphLayout(); String item = state.getClass().getSimpleName(); glyphLayout.setText(font, item); Float fwidth = glyphLayout.width; font.draw( batch, item, enemy.getX() + enemy.getWidth() / 2 - fwidth / 2, enemy.getY() + enemy.getHeight() + font.getCapHeight()); } }
void updateDisplayText() { BitmapFont font = style.font; BitmapFontData data = font.getData(); String text = this.text; int textLength = text.length(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < textLength; i++) { char c = text.charAt(i); buffer.append(data.hasGlyph(c) ? c : ' '); } String newDisplayText = buffer.toString(); if (passwordMode && data.hasGlyph(passwordCharacter)) { if (passwordBuffer == null) passwordBuffer = new StringBuilder(newDisplayText.length()); if (passwordBuffer.length() > textLength) passwordBuffer.setLength(textLength); else { for (int i = passwordBuffer.length(); i < textLength; i++) passwordBuffer.append(passwordCharacter); } displayText = passwordBuffer; } else displayText = newDisplayText; layout.setText(font, displayText); glyphPositions.clear(); float x = 0; if (layout.runs.size > 0) { GlyphRun run = layout.runs.first(); FloatArray xAdvances = run.xAdvances; fontOffset = xAdvances.first(); for (int i = 1, n = xAdvances.size; i < n; i++) { glyphPositions.add(x); x += xAdvances.get(i); } } else fontOffset = 0; glyphPositions.add(x); if (selectionStart > newDisplayText.length()) selectionStart = textLength; }
@Override public void onDrawItem(Object data, Batch batch, int x, int y, int width, int height) { if (data instanceof AbilityTree && ((AbilityTree) data).current.current instanceof ActiveAbility) { ActiveAbility aa = (ActiveAbility) ((AbilityTree) data).current.current; if (!aa.isAvailable()) { batch.setColor(0.1f, 0.1f, 0.1f, 0.75f); batch.draw(white, x, y, width, height); batch.setColor(Color.WHITE); int cooldown = (int) Math.ceil(aa.cooldownAccumulator); if (cooldown > 0) { String text = aa.cooldownType.text + "\n" + cooldown; layout.setText(font, text, Color.WHITE, 0, Align.center, false); font.draw(batch, layout, x + width / 2, y + height / 2 + layout.height / 2); } } } }
public void render(float delta) { secondsElapsed += delta; camera.update(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); backgroundSprite.draw(batch); layout.setText(title, "Meteoric"); title.draw( batch, layout, game.WIDTH / 2 - layout.width / 2, game.HEIGHT * 3 / 4 - layout.height / 2); layout.setText(bitmap, game.getBundle().get("touch1")); bitmap.draw( batch, layout, game.WIDTH / 2 - layout.width / 2, game.HEIGHT / 2 - layout.height / 2); layout.setText(bitmap, game.getBundle().get("touch3")); bitmap.draw( batch, layout, game.WIDTH / 2 - layout.width / 2, game.HEIGHT / 3 + layout.height + 4); layout.setText(bitmap, game.getBundle().get("touch4")); bitmap.draw(batch, layout, game.WIDTH / 2 - layout.width / 2, game.HEIGHT / 3); layout.setText(bitmap, game.getBundle().get("touch5")); bitmap.draw( batch, layout, game.WIDTH / 2 - layout.width / 2, game.HEIGHT / 3 - layout.height - 4); layout.setText(bitmap, "Record: " + game.MAXSCORE + " " + maxLevel); bitmap.draw(batch, layout, game.WIDTH / 8, game.HEIGHT); batch.draw( meteorAnimation.getKeyFrame(secondsElapsed, true), game.WIDTH / 2 - width / 2, game.HEIGHT / 10, width, height); batch.end(); }
public void render(Batch b) { if (!isVisible()) { return; } if (Cvars.Client.Console.Height.getValue() == 0.0f) { b.draw( modelBackgroundTexture, 0.0f, 0.0f, getClient().getVirtualWidth(), getClient().getVirtualHeight()); b.draw(underlineBackgroundTexture, 0.0f, height, getClient().getVirtualWidth(), 2.0f); } else { b.draw( modelBackgroundTexture, 0.0f, height, getClient().getVirtualWidth(), getClient().getVirtualHeight() - height); b.draw( underlineBackgroundTexture, 0.0f, height + font.getLineHeight() + 2.0f, getClient().getVirtualWidth(), 2.0f); } String bufferSnapshot = getBuffer(); GlyphLayout glyphs = font.draw(b, getBufferPrefix() + " " + bufferSnapshot, 0, height + font.getLineHeight()); glyphs.setText(font, getBufferPrefix() + " " + bufferSnapshot.substring(0, getPosition())); float x = glyphs.width; float width; if (!isBufferEmpty() && getPosition() < getBufferLength()) { char c = bufferSnapshot.charAt(getPosition()); if (Character.isSpaceChar(c)) { width = font.getSpaceWidth(); } else { glyphs.setText(font, Character.toString(c)); width = glyphs.width - 4; } } else { width = font.getSpaceWidth(); } CARET.render(b, font, glyphs, x, height + 4, width, 1.0f); float lineY; if (Cvars.Client.Console.Height.getValue() == 0.0f) { lineY = font.getLineHeight(); } else { lineY = height + 4.0f + (font.getLineHeight() * 2); } int skip = outputOffset; for (String line : getOutput()) { if (Cvars.Client.Console.Height.getValue() == 0.0f && lineY >= height + font.getLineHeight()) { break; } if (skip > 0) { skip--; continue; } font.draw(b, line, 0.0f, lineY); lineY += font.getLineHeight(); } int position = getPosition(); Set<String> suggestions = new TreeSet<String>(); for (CommandProcessor commandProcessor : getCommandProcessors()) { for (Command command : commandProcessor.getSuggestions(bufferSnapshot, position)) { suggestions.add(command.toString()); } } if (!suggestions.isEmpty()) { glyphs.setText(font, getBufferPrefix() + " " + bufferSnapshot.substring(0, getPosition())); x = glyphs.width; float y = height; if (Cvars.Client.Console.Height.getValue() == 1.0f) { y += suggestions.size() * font.getLineHeight() + font.getLineHeight(); } float maxWidth = 0.0f; for (String suggestion : suggestions) { glyphs.setText(font, suggestion); maxWidth = Math.max(maxWidth, glyphs.width); } b.draw( suggestionBackgroundTexture, x, y - suggestions.size() * font.getLineHeight(), maxWidth, suggestions.size() * font.getLineHeight()); for (String suggestion : suggestions) { font.draw(b, suggestion, x, y); y -= font.getLineHeight(); } } }
@Override public void show() { state = State.INITIALIZING; setBackground(Assets.bg); getBackgroundBounds().x = -100; getBackgroundBounds().y = -100; getBackgroundBounds().width = EatFishAndAI.WIDTH + 200; getBackgroundBounds().height = EatFishAndAI.HEIGHT + 200; spawner = new DummySpawner(); spawner.setGameContext(getGameContext()); gameNameLayout = new GlyphLayout(); gameNameLayout.setText(Assets.font30, conf.gamename); // Preset predator ai // int offset = 100; // getGameContext().spawn( // new PredatorFish(EatFishAndAI.WIDTH - offset, // EatFishAndAI.HEIGHT - offset)); // getGameContext().spawn( // new PredatorFish(EatFishAndAI.WIDTH - offset, offset)); // getGameContext().spawn( // new PredatorFish(offset, EatFishAndAI.HEIGHT - offset)); // getGameContext().spawn(new PredatorFish(offset, offset)); List<AIFactory<?>> factories = conf.aiconf.getAIs(); int count = factories.size(), radius = 150; float angle = (float) (2 * Math.PI / count); float angleOffset = (float) (Math.PI / 4); float randomOffset = (float) ((int) (Math.random() * 4) * Math.PI / 2); System.out.println(randomOffset); boolean newGame = conf.players.isEmpty(); for (int i = 0; i < conf.aiconf.getAIs().size(); i++) { PlayerFish player; if (newGame) { player = new PlayerFish( (float) (centerX - PlayerFish.WIDTH / 2 + Math.cos(i * angle + angleOffset + randomOffset) * radius), (float) (centerY - PlayerFish.HEIGHT / 2 + Math.sin(i * angle + angleOffset + randomOffset) * radius)); conf.players.add(player); } else { player = conf.players.get(i); player.killAI(); player.setX( (float) (centerX - PlayerFish.WIDTH / 2 + Math.cos(i * angle + angleOffset + randomOffset) * radius)); player.setY( (float) (centerY - PlayerFish.HEIGHT / 2 + Math.sin(i * angle + angleOffset + randomOffset) * radius)); player.setVelocityX(0); player.setVelocityY(0); player.setMaxSpeed(PlayerFish.MAX_SPEED); player.setScale(PlayerFish.STARTING_SCALE); player.setAlive(true); } getGameContext().spawn(player); player.setGameContext(getGameContext()); player.attachAI(factories.get(i).newInstance()); player.start(); } conf.playersAlive = new ArrayList<>(conf.players); getGameContext().spawn(new RoundScore(conf, playerListX, playerListY)); CustomTextButton stopButton = new CustomTextButton(EatFishAndAI.WIDTH - CustomTextButton.WIDTH, 0, "STOP"); stopButton.setButtonListener( new ButtonListener() { @Override public void handle(ButtonAction ba) { if (ba.type == TYPE.RELEASE) { game.setScreen(new MenuScreen((EatFishAndAI) game)); } } }); CustomTextButton killButton = new CustomTextButton(EatFishAndAI.WIDTH - 2 * CustomTextButton.WIDTH, 0, "KILL"); killButton.setButtonListener( new ButtonListener() { @Override public void handle(ButtonAction ba) { if (ba.type == TYPE.RELEASE) { PlayerFish biggest = conf.playersAlive.get(0); for (PlayerFish o : conf.playersAlive) { if (o.getScale() > biggest.getScale()) { biggest = o; } } while (conf.playersAlive.size() > 1) { int randomIndex = (int) (Math.random() * conf.playersAlive.size()); PlayerFish fish = conf.playersAlive.get(randomIndex); if (fish.equals(biggest)) { continue; } conf.playersAlive.remove(fish); fish.destroy(); } } } }); getGameContext().spawn(killButton); getGameContext().spawn(stopButton); state = State.STARTING; Timeline all = Timeline.createSequence(); for (PlayerFish player : conf.playersAlive) { all.push(CommonTweens.zoomAtGameObject(player, getCamera(), 3.0f, 1.0f)); } all.push(CommonTweens.zoomAtPoint(centerX, centerY, getCamera(), 1.0f, 1.0f)); all.setCallback( new TweenCallback() { @Override public void onEvent(int type, BaseTween<?> source) { if (type == TweenCallback.COMPLETE) { state = State.PLAYING; getGameContext().setPaused(false); } } }); GlobalTween.add(all); getGameContext().spawn(new OverallScore(conf, EatFishAndAI.WIDTH - 300, EatFishAndAI.HEIGHT)); getGameContext().update(1); getGameContext().setPaused(true); }
private static float getWidth(BitmapFont font, String chr) { glyphLayout.setText(font, chr); return glyphLayout.width; }