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

The following examples show how to use com.badlogic.gdx.graphics.g2d.SpriteBatch#setTransformMatrix() . 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: MainMenu.java    From Radix with MIT License 6 votes vote down vote up
public void init() {
    if (!initialized) {
        camera = new OrthographicCamera();
        batch = new SpriteBatch();
        batch.setTransformMatrix(RadixClient.getInstance().getHudCamera().combined);
        batch.setTransformMatrix(camera.combined);
        mmButtonTexture = new Texture(Gdx.files.internal("textures/gui/mmBtn.png"));

        buttonFont = new BitmapFont();

        resize();
        rerender();

        initialized = true;
    }
}
 
Example 2
Source File: NavMeshDebugDrawer.java    From GdxDemo3D with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ShaderTest.java    From seventh with GNU General Public License v2.0 6 votes vote down vote up
/**
     * 
     */
    public ShaderTest() {        
        ShaderProgram.pedantic = false;
        
        vertBlur = loadShader("blurv.frag");
        horBlur = loadShader("blurh.frag");
        light = loadShader("light.frag");
        
        shader = loadShader("inprint.frag");
        
        this.camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        this.camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//        camera.setToOrtho(false);
        transform = new Matrix4();
        camera.update();
        batch = new SpriteBatch();//1024, shader);
        batch.setShader(null);
        batch.setProjectionMatrix(camera.combined);
        batch.setTransformMatrix(transform);
        
        this.buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);    
        
        this.fboPing = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
        this.fboPong = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    }
 
Example 4
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 5
Source File: GameRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
private void batchAfterPostProcessing () {
	SpriteBatch batch = batchRenderer.beginTopLeft();
	batch.setTransformMatrix(xform);

	GameEvents.gameRenderer.batch = batch;
	GameEvents.gameRenderer.trigger(this, GameRendererEvent.Type.BatchAfterPostProcessing);
	batchRenderer.end();
}
 
Example 6
Source File: GameRenderer.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
public void debugRender () {
	if (debug) {
		SpriteBatch batch = batchRenderer.beginTopLeft();

		batch.setTransformMatrix(xform);
		batch.disableBlending();
		GameEvents.gameRenderer.batch = batch;
		GameEvents.gameRenderer.trigger(this, GameRendererEvent.Type.BatchDebug);
		batchRenderer.end();

		batch.setTransformMatrix(identity);
		GameEvents.gameRenderer.batch = null;
		GameEvents.gameRenderer.trigger(this, GameRendererEvent.Type.Debug);
	}
}
 
Example 7
Source File: ParticleRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) {

	float finalScaleX = EngineAssetManager.getInstance().getScale() * scaleX;
	float finalScaleY = EngineAssetManager.getInstance().getScale() * scaleY;

	if (effect.getEmitters().size > 0) {

		Matrix4 tm = batch.getTransformMatrix();
		tmp.set(tm);

		if (tmpPosX != x / finalScaleX || tmpPosY != y / finalScaleY) {
			tmpPosX = x / finalScaleX;
			tmpPosY = y / finalScaleY;

			effect.setPosition(tmpPosX, tmpPosY);
		}

		tm.rotate(0, 0, 1, rotation).scale(finalScaleX, finalScaleY, 1);

		batch.setTransformMatrix(tm);

		if (tint != null)
			batch.setColor(tint);

		effect.draw(batch);

		if (tint != null)
			batch.setColor(Color.WHITE);

		batch.setTransformMatrix(tmp);
	} else {
		x = x - getWidth() / 2 * finalScaleX;
		RectangleRenderer.draw(batch, x, y, getWidth() * finalScaleX, getHeight() * finalScaleY, Color.RED);
	}
}
 
Example 8
Source File: SpineRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) {

	SkeletonCacheEntry cs = (SkeletonCacheEntry) currentSource;

	if (cs != null && cs.skeleton != null) {
		Matrix4 tm = batch.getTransformMatrix();
		tmp.set(tm);

		float originX = cs.skeleton.getRootBone().getX();
		float originY = cs.skeleton.getRootBone().getY();
		tm.translate(x, y, 0).rotate(0, 0, 1, rotation).scale(scaleX, scaleY, 1).translate(originX, originY, 0);

		// cs.skeleton.setX(x / scale);
		// cs.skeleton.setY(y / scale);

		batch.setTransformMatrix(tm);

		if (tint != null)
			cs.skeleton.setColor(tint);

		renderer.draw(batch, cs.skeleton);

		if (tint != null)
			batch.setColor(Color.WHITE);
		batch.setTransformMatrix(tmp);
	} else {
		float dx = getAlignDx(getWidth(), orgAlign);
		float dy = getAlignDy(getHeight(), orgAlign);

		RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY,
				Color.RED);
	}
}
 
Example 9
Source File: DebugCarEngineVolumes.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
@Override
public void renderBatch (SpriteBatch batch) {
	if (isActive() && meters.size > 0) {
		Matrix4 prev = batch.getTransformMatrix();
		batch.setTransformMatrix(idt);
		batch.enableBlending();

		float prevHeight = 0;
		int index = 0;
		int drawx = 410;
		int drawy = 0;

		SpriteBatchUtils.drawString(batch, "car engine soundset", drawx, drawy);
		SpriteBatchUtils.drawString(batch, "=======================", drawx, drawy + Art.DebugFontHeight);

		String text;
		for (DebugMeter m : meters) {
			int x = drawx, y = drawy + Art.DebugFontHeight * 2;

			// offset by index
			y += index * (prevHeight + 1);

			// compute color
			float alpha = 1;
			Color c = ColorUtils.paletteRYG(1.5f - m.getValue() * 1.5f, alpha);

			{
				// render track number
				text = sampleNames[index];
				batch.setColor(1, 1, 1, alpha);
				SpriteBatchUtils.drawString(batch, text, x, y);
				batch.setColor(1, 1, 1, 1);

				// render meter after text
				int meter_x = x + (text.length() * Art.DebugFontWidth) + 2;
				m.color.set(c);
				m.setPosition(meter_x, y);
				m.render(batch);

				// render volume numerical value
				text = String.format("%.02f", m.getValue());
				batch.setColor(1, 1, 1, alpha);
				SpriteBatchUtils.drawString(batch, text, meter_x + m.getWidth() + 2, y);
				batch.setColor(1, 1, 1, 1);
			}

			index++;
			prevHeight = m.getHeight();
		}

		batch.setTransformMatrix(prev);
		batch.disableBlending();
	}
}
 
Example 10
Source File: DebugMusicVolumes.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
@Override
public void renderBatch (SpriteBatch batch) {
	if (isActive() && meters.size > 0) {
		Matrix4 prev = batch.getTransformMatrix();
		batch.setTransformMatrix(idt);
		batch.enableBlending();

		float prevHeight = 0;
		int index = 0;
		int drawx = 275;
		int drawy = 0;

		int maxMusicIndex = tensiveMusic.getCurrentMusicIndexLimit();
		SpriteBatchUtils.drawString(batch, "music tracks max=" + maxMusicIndex, drawx, drawy);
		SpriteBatchUtils.drawString(batch, "==================", drawx, drawy + Art.DebugFontHeight);

		String text;
		for (DebugMeter m : meters) {
			int x = drawx, y = drawy + Art.DebugFontHeight * 2;

			// offset by index
			y += index * (prevHeight + 1);

			// compute color
			float alpha = index > maxMusicIndex ? 0.5f : 1;
			Color c = ColorUtils.paletteRYG(1.5f - m.getValue() * 1.5f, alpha);

			{
				// render track number
				text = "T" + (index + 1);
				batch.setColor(1, 1, 1, alpha);
				SpriteBatchUtils.drawString(batch, text, x, y);
				batch.setColor(1, 1, 1, 1);

				// render meter after text
				int meter_x = x + (text.length() * Art.DebugFontWidth) + 2;
				m.color.set(c);
				m.setPosition(meter_x, y);
				m.render(batch);

				// render volume numerical value
				text = String.format("%.02f", m.getValue());
				batch.setColor(1, 1, 1, alpha);
				SpriteBatchUtils.drawString(batch, text, meter_x + m.getWidth() + 2, y);
				batch.setColor(1, 1, 1, 1);
			}

			index++;
			prevHeight = m.getHeight();
		}

		SpriteBatchUtils.drawString(batch, "total volume = " + String.format("%.02f", totalVolume), drawx, Art.DebugFontHeight
			* (meters.size + 3));

		batch.setTransformMatrix(prev);
		batch.disableBlending();
	}
}
 
Example 11
Source File: TextRenderer.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(SpriteBatch batch, float x, float y, float scaleX, float scaleY, float rotation, Color tint) {

	float dx = getAlignDx(getWidth(), orgAlign);
	float dy = getAlignDy(getHeight(), orgAlign);

	if (font != null && text != null) {

		if (tint != null && !tint.equals(color)) {
			color.set(tint);

			String tt = text;

			if (tt.charAt(0) == I18N.PREFIX)
				tt = world.getI18N().getString(tt.substring(1));

			if (editorTranslatedText != null)
				tt = editorTranslatedText;

			layout.setText(font, tt, color, 0, textAlign, false);
		}

		Matrix4 tm = batch.getTransformMatrix();
		tmp.set(tm);

		float originX = dx;
		float originY = layout.height + dy;

		if (textAlign == Align.right)
			originX += getWidth();
		else if (textAlign == Align.center)
			originX += getWidth() / 2;

		tm.translate(x, y, 0).rotate(0, 0, 1, rotation).scale(scaleX, scaleY, 1).translate(originX, originY, 0);

		batch.setTransformMatrix(tm);

		font.draw(batch, layout, 0, 0);

		batch.setTransformMatrix(tmp);
	} else {
		RectangleRenderer.draw(batch, x + dx * scaleX, y + dy * scaleY, getWidth() * scaleX, getHeight() * scaleY,
				Color.RED);
	}
}
 
Example 12
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);
}