Java Code Examples for com.badlogic.gdx.graphics.g2d.SpriteBatch#begin()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.SpriteBatch#begin() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLTFBinaryExporter.java From gdx-gltf with Apache License 2.0 | 6 votes |
public void export(GLTFImage image, Texture texture, String baseName) { String fileName = baseName + ".png"; image.uri = fileName; FileHandle file = folder.child(fileName); FrameBuffer fbo = new FrameBuffer(texture.getTextureData().getFormat(), texture.getWidth(), texture.getHeight(), false); fbo.begin(); Gdx.gl.glClearColor(0, 0, 0, 0); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); SpriteBatch batch = new SpriteBatch(); batch.getProjectionMatrix().setToOrtho2D(0, 0, 1, 1); batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE); batch.begin(); batch.draw(texture, 0, 0, 1, 1, 0, 0, 1, 1); batch.end(); Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight()); fbo.end(); batch.dispose(); fbo.dispose(); savePNG(file, pixmap); pixmap.dispose(); }
Example 2
Source File: OnscreenControls.java From ud406 with MIT License | 6 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.moveLeft, moveLeftCenter, Constants.BUTTON_CENTER ); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.moveRight, moveRightCenter, Constants.BUTTON_CENTER ); // TODO: Render the shoot and jump buttons, using the shootCenter and jumpCenter defined below batch.end(); }
Example 3
Source File: LivingEntity.java From TerraLegion with MIT License | 6 votes |
public void renderHealthBar(SpriteBatch sb) { float renderX = x + (drawable.getWidth() / 2) - (healthBarWidth / 2); float renderY = y + (drawable.getHeight() + 5); float currentHealthWidth = health * (healthBarWidth / maxHealth); if (currentHealthWidth < 0) currentHealthWidth = 0; sb.end(); shapeRenderer.setProjectionMatrix(sb.getProjectionMatrix()); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setColor(Color.RED); shapeRenderer.rect(renderX, renderY, healthBarWidth, healthBarHeight); shapeRenderer.setColor(Color.GREEN); shapeRenderer.rect(renderX, renderY, currentHealthWidth, healthBarHeight); shapeRenderer.end(); sb.begin(); }
Example 4
Source File: InventoryScreen.java From TerraLegion with MIT License | 6 votes |
@Override public void render(SpriteBatch sb) { sb.begin(); sb.setProjectionMatrix(camera.combined); sb.draw(bg, 0, 0); itemNameLabel.render(sb); itemInfoLabel.render(sb); cancelBtn.render(sb); craftingBtn.render(sb); invBtn.render(sb); dropBtn.render(sb); splitBtn.render(sb); stage.draw(); sb.end(); }
Example 5
Source File: Level.java From ud406 with MIT License | 5 votes |
public void render(SpriteBatch batch) { batch.begin(); for (Platform platform : platforms) { platform.render(batch); } gigaGal.render(batch); batch.end(); }
Example 6
Source File: Level.java From ud406 with MIT License | 5 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); for (Platform platform : platforms) { platform.render(batch); } exitPortal.render(batch); for (Powerup powerup : powerups) { powerup.render(batch); } for (Enemy enemy : enemies) { enemy.render(batch); } gigaGal.render(batch); for (Bullet bullet : bullets) { bullet.render(batch); } for (Explosion explosion : explosions) { explosion.render(batch); } batch.end(); }
Example 7
Source File: Level.java From ud406 with MIT License | 5 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); for (Platform platform : platforms) { platform.render(batch); } exitPortal.render(batch); for (Powerup powerup : powerups) { powerup.render(batch); } for (Enemy enemy : enemies) { enemy.render(batch); } gigaGal.render(batch); for (Bullet bullet : bullets) { bullet.render(batch); } for (Explosion explosion : explosions) { explosion.render(batch); } batch.end(); }
Example 8
Source File: OnscreenControls.java From ud406 with MIT License | 5 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.moveLeft, moveLeftCenter, Constants.BUTTON_CENTER ); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.moveRight, moveRightCenter, Constants.BUTTON_CENTER ); // TODO: Render the shoot and jump buttons, using the shootCenter and jumpCenter defined below Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.shoot, shootCenter, Constants.BUTTON_CENTER ); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.jump, jumpCenter, Constants.BUTTON_CENTER ); batch.end(); }
Example 9
Source File: SceneList.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
private TextureRegion createBgIcon(String atlas, String region) { TextureAtlas a = new TextureAtlas( Gdx.files.absolute(Ctx.project.getAssetPath() + Project.ATLASES_PATH + "/1/" + atlas + ".atlas")); AtlasRegion r = a.findRegion(region); if (r == null) { a.dispose(); return null; } GLFrameBuffer.FrameBufferBuilder frameBufferBuilder = new GLFrameBuffer.FrameBufferBuilder(200, (int) (r.getRegionHeight() * 200f / r.getRegionWidth())); frameBufferBuilder.addColorTextureAttachment(GL30.GL_RGBA8, GL30.GL_RGBA, GL30.GL_UNSIGNED_BYTE); FrameBuffer fbo = frameBufferBuilder.build(); SpriteBatch fboBatch = new SpriteBatch(); fboBatch.setColor(Color.WHITE); OrthographicCamera camera = new OrthographicCamera(); camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight()); fboBatch.setProjectionMatrix(camera.combined); Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST); fbo.begin(); fboBatch.begin(); fboBatch.draw(r, 0, 0, fbo.getWidth(), fbo.getHeight()); fboBatch.end(); TextureRegion tex = ScreenUtils.getFrameBufferTexture(0, 0, fbo.getWidth(), fbo.getHeight()); // tex.flip(false, true); fbo.end(); Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST); fbo.dispose(); a.dispose(); fboBatch.dispose(); return tex; }
Example 10
Source File: GameScreen.java From TerraLegion with MIT License | 5 votes |
@Override public void render(SpriteBatch sb) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); gameHud.renderBackground(); sb.setProjectionMatrix(camera.combined); sb.begin(); world.render(sb, camera); sb.end(); gameHud.render(camera); }
Example 11
Source File: Level.java From ud406 with MIT License | 5 votes |
public void render(SpriteBatch batch) { batch.begin(); for (Platform platform : platforms) { platform.render(batch); } gigaGal.render(batch); batch.end(); }
Example 12
Source File: Level.java From ud406 with MIT License | 5 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); for (Platform platform : platforms) { platform.render(batch); } exitPortal.render(batch); for (Powerup powerup : powerups) { powerup.render(batch); } for (Enemy enemy : enemies) { enemy.render(batch); } gigaGal.render(batch); for (Bullet bullet : bullets) { bullet.render(batch); } for (Explosion explosion : explosions) { explosion.render(batch); } batch.end(); }
Example 13
Source File: RetroSceneScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
@Override public void render(float delta) { final World world = ui.getWorld(); update(delta); // Gdx.gl.glClearColor(0, 0, 0, 1); // Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); if (world.getAssetState() != AssetState.LOADED) return; SpriteBatch batch = ui.getBatch(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // WORLD CAMERA if (world.getInventory().isVisible()) { worldViewport.setScreenY(screenViewport.getScreenY() + (int) verbUI.getHeight()); worldViewport.setScreenHeight(screenViewport.getScreenHeight() - (int) verbUI.getHeight()); world.resize(world.getWidth(), world.getHeight() * (1 - UI_SCREEN_PERCENT)); } else { worldViewport.setScreenY(screenViewport.getScreenY()); worldViewport.setScreenHeight(screenViewport.getScreenHeight()); world.resize(world.getWidth(), world.getHeight()); } worldViewport.apply(true); world.draw(); // DRAW DEBUG BBOXES if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) { renderer.setProjectionMatrix(world.getSceneCamera().combined); world.getCurrentScene().drawBBoxLines(renderer); renderer.end(); } // SCREEN CAMERA batch.setProjectionMatrix(worldViewport.getCamera().combined); batch.begin(); // DRAW DEBUG STRING if (EngineLogger.debugMode()) { drawDebugText(batch); } Transition t = world.getTransition(); t.draw(batch, worldViewport.getScreenWidth(), worldViewport.getScreenHeight()); recorder.draw(batch); testerBot.draw(batch); if (drawHotspots) drawHotspots(batch); batch.end(); worldViewportStage.draw(); // STAGE CAMERA screenViewport.apply(true); stage.draw(); }
Example 14
Source File: Level.java From ud406 with MIT License | 4 votes |
public void render(SpriteBatch batch) { batch.begin(); gigaGal.render(batch); batch.end(); }
Example 15
Source File: GigaGalHud.java From ud406 with MIT License | 4 votes |
public void render(SpriteBatch batch) { // TODO: Apply the viewport viewport.apply(); // TODO: Set the projection matrix batch.setProjectionMatrix(viewport.getCamera().combined); // TODO: Begin a batch batch.begin(); // TODO: Draw some test text in the middle of the screen font.draw(batch, "Testing, testing. Are you there, GigaGal?", viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 4, 0, Align.center, false); // TODO: End the batch batch.end(); }
Example 16
Source File: Level.java From ud406 with MIT License | 4 votes |
public void render(SpriteBatch batch) { batch.begin(); gigaGal.render(batch); batch.end(); }
Example 17
Source File: OnscreenControls.java From ud406 with MIT License | 4 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); if (!Gdx.input.isTouched(jumpPointer)) { gigaGal.jumpButtonPressed = false; jumpPointer = 0; } // TODO: If the moveLeftPointer is no longer touched, inform GigaGal and zero moveLeftPointer // TODO: Do the same for moveRightPointer Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.moveLeft, moveLeftCenter, Constants.BUTTON_CENTER ); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.moveRight, moveRightCenter, Constants.BUTTON_CENTER ); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.shoot, shootCenter, Constants.BUTTON_CENTER ); Utils.drawTextureRegion( batch, Assets.instance.onscreenControlsAssets.jump, jumpCenter, Constants.BUTTON_CENTER ); batch.end(); }
Example 18
Source File: GameOverOverlay.java From ud406 with MIT License | 4 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); float timeElapsed = Utils.secondsSince(startTime); int enemiesToShow = (int) (Constants.ENEMY_COUNT * (timeElapsed / Constants.LEVEL_END_DURATION)); for (int i = 0; i < enemiesToShow; i++){ Enemy enemy = enemies.get(i); enemy.update(0); enemy.render(batch); } font.draw(batch, Constants.GAME_OVER_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false); batch.end(); }
Example 19
Source File: CreditsScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
@Override public void render(float delta) { final SpriteBatch batch = ui.getBatch(); final int width = (int) viewport.getWorldWidth(); final int height = (int) viewport.getWorldHeight(); Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); if (style.background != null) { style.background.draw(batch, 0, 0, width, height); } scrollY += delta * SPEED * EngineAssetManager.getInstance().getScale(); float y = scrollY; if (stringHead >= credits.size()) ui.setCurrentScreen(Screens.MENU_SCREEN); for (int i = stringHead; i < credits.size(); i++) { String s = credits.get(i); char type = 'c'; // types are 'c' -> credit, 't' -> title, 'i' -> image, 's' -> space, 'm' -> // music if (s.indexOf('#') != -1) { type = s.charAt(0); s = s.substring(2); } switch (type) { case 't': y = processCreditTitle(batch, width, height, y, i, s); break; case 'i': y = processCreditImage(batch, width, height, y, i, s); break; case 's': y = processCreditSpace(height, y, i, s); break; case 'm': processCreditMusic(s); credits.remove(i); i--; break; default: y = processCreditDefault(batch, width, height, y, i, s); break; } if (y < 0) { break; } } batch.end(); }
Example 20
Source File: GameOverOverlay.java From ud406 with MIT License | 4 votes |
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); float timeElapsed = Utils.secondsSince(startTime); int enemiesToShow = (int) (Constants.ENEMY_COUNT * (timeElapsed / Constants.LEVEL_END_DURATION)); for (int i = 0; i < enemiesToShow; i++) { Enemy enemy = enemies.get(i); enemy.update(0); enemy.render(batch); } font.draw(batch, Constants.GAME_OVER_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false); batch.end(); }