Java Code Examples for com.badlogic.gdx.graphics.g2d.SpriteBatch#setProjectionMatrix()

The following examples show how to use com.badlogic.gdx.graphics.g2d.SpriteBatch#setProjectionMatrix() . 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: CraftingScreen.java    From TerraLegion with MIT License 6 votes vote down vote up
@Override
public void render(SpriteBatch sb) {
	sb.setProjectionMatrix(camera.combined);
	sb.begin();
	sb.draw(bg, 0, 0);
	itemNameLabel.render(sb);
	itemInfoLabel.render(sb);
	cancelBtn.render(sb);
	craftingBtn.render(sb);
	invBtn.render(sb);
	if (selectedRecipe != null)
		craftBtn.render(sb);
	sb.end();

	stage.draw();
}
 
Example 2
Source File: InventoryScreen.java    From TerraLegion with MIT License 6 votes vote down vote up
@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 3
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 4
Source File: RadixClient.java    From Radix with MIT License 6 votes vote down vote up
private void setupOGL() {
    camera = new PerspectiveCamera(90, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(10f, 150f, 10f);
    camera.lookAt(0, 0, 0);
    camera.near = 0.1f;
    camera.far = 450f;
    camera.update();
    hudCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    guiBatch = new SpriteBatch();
    guiBatch.setProjectionMatrix(hudCamera.combined);

    if(android) {
        setupTouchControls();
    }

    Gdx.input.setInputProcessor(new RadixInputHandler(this));

    if(settingsManager.getVisualSettings().getNonContinuous().getValue()) {
        Gdx.graphics.setContinuousRendering(false);
    }

    sceneTheme = new SceneTheme();
    sceneTheme.init();
}
 
Example 5
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 6
Source File: GigaGalHud.java    From ud406 with MIT License 6 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);
    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;
    for (int i = 1; i <= lives; i++) {
        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );
        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();
}
 
Example 7
Source File: ScreenGameMap.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
public void drawHUD(SpriteBatch batch) {
	// Update chat text:
	if (client.chatChanged()) updateChat();
	// draw Stage:
	stage.draw();
	// Render the HUD:
	hudCam.update();
	batch.setProjectionMatrix(hudCam.projection);
	batch.setTransformMatrix(hudCam.view);
	batch.begin();
	float x = -Gdx.graphics.getWidth() / 2f + 5f;
	float y = Gdx.graphics.getHeight() / 2f - 5f;
	// The only thing on the HUD is the FPS:
	font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), x, y);
	batch.end();
}
 
Example 8
Source File: InitScreen.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void render(float delta) {
	SpriteBatch batch = ui.getBatch();

	Gdx.gl.glClearColor(0, 0, 0, 1);
	Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

	batch.setProjectionMatrix(viewport.getCamera().combined);
	batch.begin();

	if (time > FADE_TIME * 2 + SCREEN_TIME) {  // EXIT INIT SCREEN
		batch.setColor(Color.WHITE);
		ui.setCurrentScreen(Screens.MENU_SCREEN);
		batch.end();
		return;
	} else if (time > FADE_TIME + SCREEN_TIME) {  // FADE_OUT
		batch.setColor(1, 1, 1, 1 - fadeTime / FADE_TIME);
	} else if (time < FADE_TIME) { // FADE IN
		batch.setColor(1, 1, 1, fadeTime / FADE_TIME);
	} else {
		fadeTime = 0;
	}

	final int viewportW = viewport.getScreenWidth();
	final int viewportH = viewport.getScreenHeight();
	final float texW = tex.getWidth() * scale;
	final float texH = tex.getHeight() * scale;
	batch.draw(tex, (viewportW - texW) / 2, (viewportH - texH) / 2, texW, texH);
	batch.setColor(Color.WHITE);

	time += delta;
	fadeTime += delta;
	batch.end();
}
 
Example 9
Source File: GigaGalHud.java    From ud406 with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, int lives, int ammo, int score) {
    viewport.apply();
    batch.setProjectionMatrix(viewport.getCamera().combined);
    batch.begin();
    final String hudString =
            Constants.HUD_SCORE_LABEL + score + "\n" +
                    Constants.HUD_AMMO_LABEL + ammo;

    font.draw(batch, hudString, Constants.HUD_MARGIN, viewport.getWorldHeight() - Constants.HUD_MARGIN);

    final TextureRegion standingRight = Assets.instance.gigaGalAssets.standingRight;

    for (int i = 1; i <= lives; i++) {

        final Vector2 drawPosition = new Vector2(
                viewport.getWorldWidth() - i * (Constants.HUD_MARGIN / 2 + standingRight.getRegionWidth()),
                viewport.getWorldHeight() - Constants.HUD_MARGIN - standingRight.getRegionHeight()
        );

        Utils.drawTextureRegion(
                batch,
                standingRight,
                drawPosition
        );
    }
    batch.end();

}
 
Example 10
Source File: Level.java    From ud406 with MIT License 5 votes vote down vote up
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 11
Source File: OnscreenControls.java    From ud406 with MIT License 5 votes vote down vote up
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 12
Source File: Level.java    From ud406 with MIT License 5 votes vote down vote up
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: SlideUpAnimation.java    From Radix with MIT License 5 votes vote down vote up
@Override
public void init() {
    super.init();
    fbo = new FrameBuffer(Pixmap.Format.RGBA4444, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    fboTex = fbo.getColorBufferTexture();
    Gdx.gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    Gdx.gl.glEnable(GL_BLEND);
    SpriteBatch batch = new SpriteBatch();
    batch.setProjectionMatrix(RadixClient.getInstance().getHudCamera().combined);
    fbo.bind();
    batch.begin();
    currentScreen.render(false, batch);
    batch.end();
    FrameBuffer.unbind();
}
 
Example 14
Source File: GameScreen.java    From TerraLegion with MIT License 5 votes vote down vote up
@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 15
Source File: VictoryOverlay.java    From ud406 with MIT License 4 votes vote down vote up
public void render(SpriteBatch batch) {

        viewport.apply();
        batch.setProjectionMatrix(viewport.getCamera().combined);
        batch.begin();

        // TODO: Render the explosions/fireworks

        for (Explosion explosion : explosions){
            explosion.render(batch);
        }

        // TODO: Draw a victory message

        font.draw(batch, Constants.VICTORY_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false);

        batch.end();

    }
 
Example 16
Source File: GameOverOverlay.java    From ud406 with MIT License 4 votes vote down vote up
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 17
Source File: RetroSceneScreen.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@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 18
Source File: FollowingCamera.java    From RuinsOfRevenge with MIT License 4 votes vote down vote up
public void loadToBatch(SpriteBatch batch) {
	batch.setProjectionMatrix(cam.projection);
	batch.setTransformMatrix(cam.view);
}
 
Example 19
Source File: VictoryOverlay.java    From ud406 with MIT License 3 votes vote down vote up
public void render(SpriteBatch batch) {

        viewport.apply();
        batch.setProjectionMatrix(viewport.getCamera().combined);
        batch.begin();

        for (Explosion explosion : explosions){
            explosion.render(batch);
        }

        font.draw(batch, Constants.VICTORY_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false);

        batch.end();

    }
 
Example 20
Source File: VictoryOverlay.java    From ud406 with MIT License 3 votes vote down vote up
public void render(SpriteBatch batch) {

        viewport.apply();
        batch.setProjectionMatrix(viewport.getCamera().combined);
        batch.begin();

        for (Explosion explosion : explosions) {
            explosion.render(batch);
        }

        font.draw(batch, Constants.VICTORY_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false);

        batch.end();

    }