private void renderTextOverlay() { fsb.begin(); String curStr; curStr = "Score " + player.score; TextBounds txtBounds = bigFont.getBounds(curStr); bigFont.setColor(Color.WHITE); bigFont.draw(fsb, curStr, 40, Globals.PSCR_H - txtBounds.height); curStr = "Shield " + player.shield; txtBounds = bigFont.getBounds(curStr); bigFont.draw(fsb, curStr, Globals.PSCR_W - 600, Globals.PSCR_H - txtBounds.height); curStr = "Health " + player.hp; txtBounds = bigFont.getBounds(curStr); bigFont.draw( fsb, curStr, Globals.PSCR_W - txtBounds.width - 100, Globals.PSCR_H - txtBounds.height); curStr = player.alive ? "ALIVE" : "DEAD"; txtBounds = bigFont.getBounds(curStr); bigFont.setColor(player.alive ? Color.GREEN : Color.RED); bigFont.draw(fsb, curStr, Globals.PSCR_W - txtBounds.width, txtBounds.height + 40); if (player.gameover) { txtBounds = hugeFont.getBounds("GAME OVER!"); float gx = (Globals.PSCR_W - txtBounds.width) / 2.0f; float gy = (Globals.PSCR_H - txtBounds.height) / 2.0f; hugeFont.draw(fsb, "GAME OVER!", gx, gy); } fsb.end(); }
@Override public void draw(Player p) { cam.setToOrtho(true, HawkthorneGame.WIDTH, HawkthorneGame.HEIGHT); cam.zoom = 1f; cam.update(true); batch.setProjectionMatrix(cam.combined); batch.begin(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); batch.draw( this.background, cam.viewportWidth / 2 - this.background.getRegionWidth() / 2, cam.viewportHeight / 2 - this.background.getRegionHeight() / 2); batch.setColor(0, 0, 0, 1); BitmapFont font = Assets.getFont(); font.setScale(0.8f, -0.8f); font.draw(batch, "SERVER", 278, 151); font.draw(batch, "CLIENT", 278, 181); batch.setColor(1, 1, 1, 1); batch.draw(this.arrow, 236, 139 + 30 * this.option); String back = Keys.toString(KeyMapping.gameKeyToInt(GameKeys.START)) + ": EXIT GAME"; String howto = "<JUMP> OR " + Keys.toString(KeyMapping.gameKeyToInt(GameKeys.JUMP)) + ": SELECT ITEM"; font.draw(batch, back, 25, 25); font.draw(batch, howto, 25, 55); font.setColor(Color.RED); font.draw(batch, warning, 60, 305); font.setColor(Color.WHITE); batch.end(); }
@Override public void draw(Batch batch, float parentAlpha) { font.setScale(getScaleX()); font.setColor(this.getColor()); font.drawWrapped(batch, text, getX(), getY(), getWidth()); font.setColor(Color.WHITE); font.setScale(1); }
public void writeLine(String text, BitmapFont font, float x, float y) { TextBounds bounds = font.getBounds(text); font.setColor(Color.BLACK); font.draw(Game.getGame().batch, text, x - bounds.width / 2 + 3, y); font.setColor(Color.WHITE); font.draw(Game.getGame().batch, text, x - bounds.width / 2, y + 3); }
private void renderGuiGameOverMessage(SpriteBatch batch) { float x = cameraGUI.viewportWidth / 2; float y = cameraGUI.viewportHeight / 2; if (worldController.isGameOver()) { BitmapFont fontGameOver = Assets.instance.fonts.defaultBig; fontGameOver.setColor(1, 0.75f, 0.25f, 1); fontGameOver.draw(batch, "GAME OVER", x, y, 0, 5, true); fontGameOver.setColor(1, 1, 1, 1); } }
public void draw(SpriteBatch batch) { if (size == 0) { titleFont.setColor(Colors.P_RED); titleFont.draw(batch, "Space", x, y); titleFont.setColor(Colors.P_YELLOW); titleFont.draw(batch, "Race!", x + 54, y - 40); } else { titleFont.setColor(Colors.P_RED); titleFont.draw(batch, "Space", x - 200, y + 50); titleFont.setColor(Colors.P_YELLOW); titleFont.draw(batch, "Race!", x - 92, y - 30); } }
public StartScreen(SpaceSim game) { this.game = game; background = new Texture(Gdx.files.internal("bg5.jpg")); batch = new SpriteBatch(); stage = new Stage(); heading = "Space Simulator"; Gdx.input.setInputProcessor(stage); FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Philosopher-Regular.ttf")); FreeTypeFontParameter parameter = new FreeTypeFontParameter(); buttonFont = generator.generateFont(parameter); buttonFont.setColor(1, 1, 1, 1); parameter.size = 72; headingFont = generator.generateFont(parameter); headingFont.setColor(1, 1, 1, 1); generator.dispose(); GlyphLayout layout = new GlyphLayout(headingFont, heading); headingX = (int) ((Gdx.graphics.getWidth() / 2) - (layout.width / 2)); headingY = 550; this.skin = new Skin(); this.skin.add("default", buttonFont); Pixmap pixmap = new Pixmap(200, 50, Pixmap.Format.RGB888); pixmap.setColor(Color.WHITE); pixmap.fill(); this.skin.add("background", new Texture(pixmap)); TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(); textButtonStyle.up = this.skin.newDrawable("background", Color.GRAY); textButtonStyle.over = this.skin.newDrawable("background", Color.LIGHT_GRAY); textButtonStyle.font = this.skin.getFont("default"); this.skin.add("default", textButtonStyle); TextButton startButton = new TextButton("Start", this.skin); startButton.addListener( new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { StartScreen.this.game.setScreen(new GalaxyMapScreen(StartScreen.this.game)); }; }); startButton.setPosition((Gdx.graphics.getWidth() / 2) - (startButton.getWidth() / 2), 300); this.stage.addActor(startButton); }
private void renderGuiFpsCounter(SpriteBatch batch) { float x = cameraGUI.viewportWidth - 55; float y = cameraGUI.viewportHeight - 15; int fps = Gdx.graphics.getFramesPerSecond(); BitmapFont fpsFont = Assets.instance.fonts.defaultNormal; if (fps > 44) { fpsFont.setColor(0, 1, 0, 1); } else if (fps > 29) { fpsFont.setColor(1, 1, 0, 1); } else { fpsFont.setColor(1, 0, 0, 1); } fpsFont.draw(batch, "FPS" + fps, x, y); fpsFont.setColor(1, 1, 1, 1); }
public void render() { // System.out.println(font.getBounds(" ").width); float textWidth = font.getBounds(text).width; // float textHeight = font.getBounds(text).height; // TextureRegion background = allocTextureRegion("grid"); // spriteBatch.setColor(0.0f, 0.0f, 0.0f, color.a * 0.7f); // spriteBatch.draw(background, // oringinX - textWidth * 0.5f - PAD, oringinY - PAD, // textWidth + PAD * 2.0f, textHeight + PAD * 2.0f); // spriteBatch.setColor(Color.WHITE); // font.get font.setColor(color); font.draw(spriteBatch, text, oringinX - textWidth * 0.5f, oringinY + font.getCapHeight()); font.setColor(Color.WHITE); }
public GameRenderer(Viewport viewport, Camera camera, GameEngine engine) { this.viewport = viewport; this.camera = camera; this.engine = engine; shapeRenderer = new MyShapeRenderer(); shapeRenderer.setAutoShapeType(true); spriteBatch = new SpriteBatch(); font = new BitmapFont(); font.setColor(Color.WHITE); font.setUseIntegerPositions(false); font.getData().setScale(0.01f); shadowBatch = new ModelBatch(new DepthShaderProvider()); ShaderProgram.pedantic = false; final String vertUber = Gdx.files.internal("shaders/uber.vert").readString(); final String fragUber = Gdx.files.internal("shaders/uber.frag").readString(); modelBatch = new ModelBatch( new DefaultShaderProvider(vertUber, fragUber) { @Override protected Shader createShader(final Renderable renderable) { return new UberShader(renderable, config); } }); }
public int drawText(AnimationState as, int x, int y, CharSequence str, int start, int end) { FontState fontState = evalFontState(as); x += fontState.offsetX; y += fontState.offsetY + yOffset; bitmapFont.setColor(renderer.getColor(fontState.color)); return bitmapFont.draw(renderer.batch, str, x, y, start, end).width; }
public FontCache cacheText(FontCache cache, CharSequence str, int start, int end) { if (cache == null) cache = new GdxFontCache(); GdxFontCache bitmapCache = (GdxFontCache) cache; bitmapFont.setColor(com.badlogic.gdx.graphics.Color.WHITE); bitmapCache.setText(str, 0, yOffset, start, end); return cache; }
@Override public void draw(SpriteBatch batch, float parentAlpha) { Drawable background; if (list != null && list.getParent() != null && style.backgroundOpen != null) background = style.backgroundOpen; else if (clickListener.isOver() && style.backgroundOver != null) background = style.backgroundOver; else background = style.background; final BitmapFont font = style.font; final Color fontColor = style.fontColor; Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); background.draw(batch, x, y, width, height); if (items.length > 0) { float availableWidth = width - background.getLeftWidth() - background.getRightWidth(); int numGlyphs = font.computeVisibleGlyphs( items[selectedIndex], 0, items[selectedIndex].length(), availableWidth); bounds.set(font.getBounds(items[selectedIndex])); height -= background.getBottomHeight() + background.getTopHeight(); float textY = (int) (height / 2 + background.getBottomHeight() + bounds.height / 2); font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha); font.draw( batch, items[selectedIndex], x + background.getLeftWidth(), y + textY, 0, numGlyphs); } // calculate screen coords where list should be displayed getStage().toScreenCoordinates(screenCoords.set(x, y), batch.getTransformMatrix()); }
Menu(TwoD game) { this.game = game; batch = new SpriteBatch(); font = new BitmapFont(); font.setColor(Color.WHITE); camera = new OrthographicCamera(); viewport = new FitViewport(1024, 786, camera); viewport.apply(); stage = new Stage(viewport, batch); stage.setDebugAll(true); gearScreen = new GearScreen(); gearScreen.setBounds(512, 0, 512, 786); inventoryScreen = new InventoryScreen(); inventoryScreen.setBounds(0, 0, 512, 786); stage.addActor(gearScreen); stage.addActor(inventoryScreen); dnd = new DragAndDrop(); inputMultiplexer = new InputMultiplexer(); inputMultiplexer.addProcessor(this); inputMultiplexer.addProcessor(stage); }
@Override public void create() { gsm = new GameStageManage(); batch = new SpriteBatch(); font = new BitmapFont(); font.setColor(Color.RED); }
// *** Methods for drawing text ***\\ public static void drawString( SpriteBatch batch, String string, float x, float y, boolean centered, float scale, Color color) { // Check if the new scale is the same as the current one. if (font_.getScaleX() != scale || font_.getScaleY() != scale) font_.setScale(scale); // No need to check the colour, as that is done in the BitmapCache in the BitmapFont. font_.setColor(color); if (centered) { TextBounds bounds = font_.getBounds(string); float width = bounds.width; float height = bounds.height - font_.getAscent(); x -= (width / 2); y -= (height / 2); } font_.draw(batch, string, x, y); }
public void Inicializar(com.juegospichurria.modelo.Mapa mapa, int filaActivo, int columnaActivo) { this.mapa = mapa; fuente = new BitmapFont(); fuente.setColor(new Color(1, 1, 1, 1)); fuente.scale(.1f); estado = new Stage(new FitViewport(qbox.Pantalla.ANCHO, qbox.Pantalla.ALTO)); this.filaActivo = filaActivo; this.columnaActivo = columnaActivo; cuadrosActores = new Array<com.juegospichurria.actores.Cuadro>(); int index = 0; for (com.juegospichurria.modelo.Cuadro cuadro : this.mapa.getCuadros()) { com.juegospichurria.actores.Cuadro cuadrillo = new com.juegospichurria.actores.Cuadro(cuadro, this); cuadrosActores.add(cuadrillo); estado.addActor(cuadrosActores.get(index)); index++; } com.juegospichurria.actores.Cuadro.cuadroActivo = obtenerActivo(); estado.addActor(reset); }
@Override public void draw(SpriteBatch batch, float parentAlpha) { final Drawable listBackground = style.listBackground; final Drawable listSelection = style.listSelection; final BitmapFont font = style.font; final Color fontColor = style.fontColor; float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); listBackground.draw(batch, x, y, width, height); width -= listBackground.getLeftWidth() + listBackground.getRightWidth(); x += listBackground.getLeftWidth(); float posY = height - listBackground.getTopHeight(); for (int i = 0; i < items.length; i++) { if (listSelectedIndex == i) { listSelection.draw(batch, x, y + posY - itemHeight, width, itemHeight); } font.setColor(fontColor.r, fontColor.g, fontColor.b, color.a * fontColor.a * parentAlpha); font.draw(batch, items[i], x + textOffsetX, y + posY - textOffsetY); posY -= itemHeight; } }
public BitmapFont getFont(String id, String fileFNT, String filePNG, Color color, float scale) { BitmapFont font = new BitmapFont(Gdx.files.internal(fileFNT), Gdx.files.internal(filePNG), false); font.setColor(color); // font.setScale(scale); return font; }
@Override public void create() { // setup the camera. In Box2D we operate on a // meter scale, pixels won't do it. So we use // an orthographic camera with a viewport of // 48 meters in width and 32 meters in height. // We also position the camera so that it // looks at (0,16) (that's where the middle of the // screen will be located). camera = new OrthographicCamera(48, 32); camera.position.set(0, 16, 0); // next we setup the immediate mode renderer renderer = new ShapeRenderer(); // next we create the box2d debug renderer debugRenderer = new Box2DDebugRenderer(); // next we create a SpriteBatch and a font batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); font.setColor(Color.RED); textureRegion = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg"))); // next we create out physics world. createPhysicsWorld(); // register ourselfs as an InputProcessor Gdx.input.setInputProcessor(this); }
public FontCache cacheMultiLineText( FontCache cache, CharSequence str, int width, de.matthiasmann.twl.HAlignment align) { if (cache == null) cache = new GdxFontCache(); GdxFontCache bitmapCache = (GdxFontCache) cache; bitmapFont.setColor(com.badlogic.gdx.graphics.Color.WHITE); bitmapCache.setMultiLineText(str, 0, yOffset, width, gdxAlignment[align.ordinal()]); return cache; }
public void draw(SpriteBatch spriteBatch) { if (!isVisible()) return; font.setColor(colorTransition.get()); SpriteBatchUtils.drawMultilineTextWithAlignment( spriteBatch, font, text, getX(), getY(), cx, cy, alignment, roundPosition); // ImmediateModeRendererUtils.drawRectangle(bounds.x, bounds.y, bounds.x + bounds.width, // bounds.y + bounds.height, Color.GREEN); }
public PortraitActor() { bitmapFont = new BitmapFont(); bitmapFont.setColor(1, 0, 0, 1); this.chosen = false; setBounds(x, y, 96, 96); addCustomListener(); update(); }
@Override public void create() { WIDTH_DEVICE = Gdx.graphics.getWidth(); HEIGHT_DEVICE = Gdx.graphics.getHeight(); ASPECT_RATIO = WIDTH_DEVICE / HEIGHT_DEVICE; WIDTH_WORLD = VIEWPORT_HEIGHT * ASPECT_RATIO; HEIGHT_WORLD = VIEWPORT_HEIGHT; // Models initialization // In the space there is not gravity :D int x_gravity = 0; int y_gravity = 0; boolean improve_performance_lowering_simulating_of_bodies = false; world = new World( new Vector2(x_gravity, y_gravity), improve_performance_lowering_simulating_of_bodies); /// Create a loader for the file saved from the editor. READ ONCE loader = new MiBodyEditorLoader(Gdx.files.internal("data/cr/world.json")); createPlanet(); createPlanetCore(); createBalls(); // Render initialization batch = new SpriteBatch(); font = new BitmapFont(); font.setColor(Color.BLACK); camera = new OrthographicCamera(); camera.setToOrtho( false, WIDTH_WORLD, HEIGHT_WORLD); // setting aspect ratio and y-axis pointing to up camera.position.set(0, camera.viewportHeight / 2, 0); camera.update(); createSprites(); // Input initialization Gdx.input.setInputProcessor( new InputAdapter() { @Override public boolean touchDown(int x, int y, int pointer, int button) { restart(); return true; } }); // Run restart(); }
@Override public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); batch.draw(split[0][animationFrame], getX(), getY()); if (state.selected == this && selectVisible) { batch.draw( PulsatioGame.getSingleton().atlas.findRegion("unit_selection_box"), getX(), getY()); } BitmapFont font = PulsatioGame.getSingleton().assets.get("b03-8.fnt", BitmapFont.class); font.setColor(Color.BLACK); font.draw(batch, "" + data.health, getX() + 1, getY() - 1); font.draw(batch, "" + data.id, getX(), getY() + 40); font.setColor(Color.GREEN); font.draw(batch, "" + data.health, getX(), getY()); font.setColor(Color.WHITE); }
private void renderGuiFpsCounter(SpriteBatch batch) { float x = cameraGUI.viewportWidth - 55; float y = cameraGUI.viewportHeight - 15; int fps = Gdx.graphics.getFramesPerSecond(); BitmapFont fpsFont = Assets.instance.fonts.defaultNormal; if (fps >= 45) { // 45 or more FPS show up in green fpsFont.setColor(0, 1, 0, 1); } else if (fps >= 30) { // 30 or more FPS show up in yellow fpsFont.setColor(1, 1, 0, 1); } else { // less than 30 FPS show up in red fpsFont.setColor(1, 0, 0, 1); } fpsFont.draw(batch, "FPS: " + fps, x, y); fpsFont.setColor(1, 1, 1, 1); }
public void draw(SpriteBatch spriteBatch) { Color oldColor = font.getColor(); if (down) { spriteBatch.setColor(Color.RED); } else { spriteBatch.setColor(Color.BLUE); } spriteBatch.draw(Assets.pureWhiteTextureRegion, x, y, w, h); spriteBatch.setColor(Color.WHITE); if (down) { font.setColor(oldColor.r / 2, oldColor.g / 2, oldColor.b / 2, oldColor.a); } float textX = x; float textY = y + h; textY -= (h - textHeight) / 2; font.drawWrapped(spriteBatch, text, textX, textY, w, alignment); font.setColor(oldColor); }
@Override public void create() { font = new BitmapFont(); font.setColor(1f, 0f, 0.05f, 1f); font.setScale(1.2f); project = ProjectManager.getInstance().getCurrentProject(); pathForScreenshot = Utils.buildProjectPath(project.getName()) + "/"; virtualWidth = project.getXmlHeader().virtualScreenWidth; virtualHeight = project.getXmlHeader().virtualScreenHeight; virtualWidthHalf = virtualWidth / 2; virtualHeightHalf = virtualHeight / 2; stage = new Stage(virtualWidth, virtualHeight, true); batch = stage.getSpriteBatch(); Gdx.gl.glViewport(0, 0, ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT); initScreenMode(); sprites = project.getSpriteList(); for (Sprite sprite : sprites) { sprite.resetSprite(); sprite.look.createBrightnessContrastShader(); stage.addActor(sprite.look); sprite.resume(); } passepartout = new Passepartout( ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT, maximizeViewPortWidth, maximizeViewPortHeight, virtualWidth, virtualHeight); stage.addActor(passepartout); 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); } axes = new Texture(Gdx.files.internal("stage/red_pixel.bmp")); skipFirstFrameForAutomaticScreenshot = true; if (checkIfAutomaticScreenshotShouldBeTaken) { makeAutomaticScreenshot = project.manualScreenshotExists(SCREENSHOT_MANUAL_FILE_NAME); } }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); textFont.setColor(Color.YELLOW); textFont.draw( batch, String.format("%4s%9s%9s", "RANK", "SCORE", "NAME"), (int) (1200 * .12), (int) (1824 * .875)); for (int i = 0; i < 10; i++) { textFont.setColor(scoreColors[i]); drawScore(i); } batch.draw(backButton.getTexture(), backButton.getX(), backButton.getY()); batch.end(); if (Gdx.input.isKeyPressed(Input.Keys.BACK)) MainGame.setScreen(new MenuScreen(MainGame)); }
@Override public void create() { batch = new SpriteBatch(); screenWidth = Gdx.graphics.getWidth(); screenHeight = Gdx.graphics.getHeight(); font = new BitmapFont(); font.setColor(Color.GREEN); font.scale(5); Gdx.input.setInputProcessor(this); }