ExtendedSpriteBatch now provides a begin() overload that needs to be used to set a projection camera instead of the old setter method. also begin() now resets the tint color
This commit is contained in:
parent
b4b83c84d6
commit
a685be02fb
|
@ -1,6 +1,7 @@
|
|||
package com.blarg.gdx.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
@ -13,9 +14,12 @@ import com.badlogic.gdx.math.Vector3;
|
|||
* are to make drawing sprites at projected screen coordinates easier.
|
||||
*
|
||||
* Projected screen coordinate sprite rendering requires a perspective camera to project the 3D coordinates correctly.
|
||||
* A camera _must_ be set via {@link #setProjectionCamera} before any of these draw methods are called.
|
||||
* A camera _must_ be set via {@link #begin(Camera)} (instead of using {@link #begin()}) before any of these draw
|
||||
* methods are called.
|
||||
*/
|
||||
public class ExtendedSpriteBatch extends SpriteBatch {
|
||||
static final float DEFAULT_COLOR = Color.WHITE.toFloatBits();
|
||||
|
||||
static final Vector3 tmp1 = new Vector3();
|
||||
|
||||
Camera projectionCamera;
|
||||
|
@ -41,16 +45,29 @@ public class ExtendedSpriteBatch extends SpriteBatch {
|
|||
super(size, buffers, defaultShader);
|
||||
}
|
||||
|
||||
public void setProjectionCamera(Camera camera) {
|
||||
this.projectionCamera = camera;
|
||||
}
|
||||
|
||||
public void setPixelScale(int pixelScale) {
|
||||
if (pixelScale <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
this.pixelScale = pixelScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin() {
|
||||
super.begin();
|
||||
setColor(DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
public void begin(Camera projectionCamera) {
|
||||
begin();
|
||||
this.projectionCamera = projectionCamera;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
super.end();
|
||||
this.projectionCamera = null;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
public void draw(Texture texture, float x, float y, float z) {
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package com.blarg.gdx.graphics;
|
||||
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
public final class GraphicsHelpers {
|
||||
public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, BitmapFont font, Vector3 origin) {
|
||||
renderCoordinateSystemAxis(shapeRenderer, spriteBatch, font, origin, 5.0f);
|
||||
public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin) {
|
||||
renderCoordinateSystemAxis(shapeRenderer, spriteBatch, projectionCamera, font, origin, 5.0f);
|
||||
}
|
||||
|
||||
public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, BitmapFont font, Vector3 origin, float axisLength) {
|
||||
public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin, float axisLength) {
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
spriteBatch.begin();
|
||||
spriteBatch.begin(projectionCamera);
|
||||
|
||||
shapeRenderer.setColor(Color.WHITE);
|
||||
shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + axisLength, origin.z + 0.0f);
|
||||
|
|
|
@ -80,7 +80,6 @@ public class RenderContext implements Disposable {
|
|||
|
||||
public void onPreRender() {
|
||||
spriteBatch.setProjectionMatrix(orthographicCamera.combined);
|
||||
spriteBatch.setProjectionCamera(perspectiveCamera);
|
||||
spriteBatch.setPixelScale(pixelScaler.getScale());
|
||||
debugGeometryRenderer.setProjectionMatrix(perspectiveCamera.combined);
|
||||
billboardSpriteBatch.begin(decalBatch, perspectiveCamera);
|
||||
|
|
Loading…
Reference in a new issue