List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch getTransformMatrix
@Override
public Matrix4 getTransformMatrix()
From source file:com.anstrat.gui.SnapScrollPane.java
License:Apache License
@Override public void draw(SpriteBatch batch, float parentAlpha) { if (widget == null) return;//from w ww.ja v a2 s .c om validate(); // Setup transform for this group. applyTransform(batch, computeTransform()); if (scrollX) hKnobBounds.x = hScrollBounds.x + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX()); if (scrollY) vKnobBounds.y = vScrollBounds.y + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY())); // Calculate the widget's position depending on the scroll state and available widget area. float y = widgetAreaBounds.y; if (!scrollY) y -= (int) maxY; else y -= (int) (maxY - visualAmountY); if (scrollbarsOnTop && scrollX) { float scrollbarHeight = 0; if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight(); if (style.hScroll != null) scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight()); y += scrollbarHeight; } float x = widgetAreaBounds.x; if (scrollX) x -= (int) visualAmountX; widget.setPosition(x, y); if (widget instanceof Cullable) { widgetCullingArea.x = -widget.getX() + widgetAreaBounds.x; widgetCullingArea.y = -widget.getY() + widgetAreaBounds.y; widgetCullingArea.width = widgetAreaBounds.width; widgetCullingArea.height = widgetAreaBounds.height; ((Cullable) widget).setCullingArea(widgetCullingArea); } // Caculate the scissor bounds based on the batch transform, the available widget area and the camera transform. We need to // project those to screen coordinates for OpenGL ES to consume. ScissorStack.calculateScissors(getStage().getCamera(), batch.getTransformMatrix(), widgetAreaBounds, scissorBounds); // Draw the background ninepatch. Color color = getColor(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); if (style.background != null) style.background.draw(batch, 0, 0, getWidth(), getHeight()); batch.flush(); // Enable scissors for widget area and draw the widget. if (ScissorStack.pushScissors(scissorBounds)) { drawChildren(batch, parentAlpha); ScissorStack.popScissors(); } // Render scrollbars and knobs on top. batch.setColor(color.r, color.g, color.b, color.a * parentAlpha * Interpolation.fade.apply(fadeAlpha / fadeAlphaSeconds)); if (scrollX && scrollY) { if (style.corner != null) { style.corner.draw(batch, hScrollBounds.x + hScrollBounds.width, hScrollBounds.y, vScrollBounds.width, vScrollBounds.y); } } if (scrollX) { if (style.hScroll != null) style.hScroll.draw(batch, hScrollBounds.x, hScrollBounds.y, hScrollBounds.width, hScrollBounds.height); if (style.hScrollKnob != null) style.hScrollKnob.draw(batch, hKnobBounds.x, hKnobBounds.y, hKnobBounds.width, hKnobBounds.height); } if (scrollY) { if (style.vScroll != null) style.vScroll.draw(batch, vScrollBounds.x, vScrollBounds.y, vScrollBounds.width, vScrollBounds.height); if (style.vScrollKnob != null) style.vScrollKnob.draw(batch, vKnobBounds.x, vKnobBounds.y, vKnobBounds.width, vKnobBounds.height); } resetTransform(batch); }
From source file:com.bladecoder.engine.model.Sprite3DRenderer.java
License:Apache License
@Override public void draw(SpriteBatch batch, float x, float y, float scale) { x = x - getWidth() / 2 * scale;// w ww. ja va2s . c o m if (USE_FBO) { batch.draw(tex, x, y, 0, 0, width, height, scale, scale, 0); } else { float p0x, p0y, pfx, pfy; Vector3 tmp = new Vector3(); // TODO Make static for performance? updateViewport(); // get screen coords for x and y tmp.set(x, y, 0); tmp.mul(batch.getTransformMatrix()); tmp.prj(batch.getProjectionMatrix()); p0x = VIEWPORT.width * (tmp.x + 1) / 2; p0y = VIEWPORT.height * (tmp.y + 1) / 2; tmp.set(x + width * scale, y + height * scale, 0); tmp.mul(batch.getTransformMatrix()); tmp.prj(batch.getProjectionMatrix()); pfx = VIEWPORT.width * (tmp.x + 1) / 2; pfy = VIEWPORT.height * (tmp.y + 1) / 2; batch.end(); Gdx.gl20.glViewport((int) (p0x + VIEWPORT.x), (int) (p0y + VIEWPORT.y), (int) (pfx - p0x), (int) (pfy - p0y)); Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling ? GL20.GL_COVERAGE_BUFFER_BIT_NV : 0)); drawModel(); Gdx.gl20.glViewport((int) VIEWPORT.x, (int) VIEWPORT.y, (int) VIEWPORT.width, (int) VIEWPORT.height); batch.begin(); } }
From source file:com.bladecoder.engine.spine.SpineRenderer.java
License:Apache License
@Override public void draw(SpriteBatch batch, float x, float y, float scale) { if (currentSource != null && currentSource.skeleton != null) { currentSource.skeleton.setX(x / scale); currentSource.skeleton.setY(y / scale); batch.setTransformMatrix(batch.getTransformMatrix().scale(scale, scale, 1.0f)); renderer.draw(batch, currentSource.skeleton); batch.setTransformMatrix(batch.getTransformMatrix().scale(1 / scale, 1 / scale, 1.0f)); } else {/*www .j a va2 s .com*/ x = x - getWidth() / 2 * scale; RectangleRenderer.draw(batch, x, y, getWidth() * scale, getHeight() * scale, Color.RED); } }
From source file:com.gsn.engine.template.GsnLabel.java
License:Apache License
@Override public void draw(SpriteBatch batch, float parentAlpha) { validate();//from w ww . j a va 2 s . com camera.combined.set(batch.getProjectionMatrix()).mul(batch.getTransformMatrix()); vector.set(x, y, 0); camera.project(vector); batch.end(); sprite.begin(); cache.setPosition(vector.x, vector.y); cache.draw(sprite, color.a * parentAlpha); sprite.end(); batch.begin(); }
From source file:com.ridiculousRPG.animation.WeatherEffectLayer.java
License:Apache License
/** * Draw the effect-layer.//from w ww . ja v a2 s .c o m */ public void draw(SpriteBatch batch, Camera cam, boolean debug) { if (flip) { batch.setTransformMatrix(compTransMatrix(batch, cam)); } if (fadeAlpha < 1f) { Color c = batch.getColor(); c.a *= fadeAlpha; batch.setColor(c); fadeAlpha += fadeBy * Gdx.graphics.getDeltaTime(); if (fadeAlpha > 1f) fadeAlpha = 1f; } // load frequently used variables into registers Texture t = tRef.getTexture(); int tWidth = tRef.getRegionWidth(); int tHeight = tRef.getRegionHeight(); float x1 = Math.max(0f, cam.position.x); float y1 = Math.max(0f, cam.position.y); float x2 = Math.min(width, x1 + cam.viewportWidth); float y2 = Math.min(height, y1 + cam.viewportHeight); float x3 = x1 - tWidth; float y3 = y1 - tHeight; float x4 = x2 - tWidth; float y4 = y2 - tHeight; for (List<Rectangle> row : tileLayer) { for (Rectangle clip : row) { float x = clip.x; float y = clip.y; if (x > x3 && y > y3 && x < x2 && y < y2) { // texel space origin is upper left corner (unlike screen // space) int srcX = 0; int srcY = 0; int srcWidth = tWidth; int srcHeight = tHeight; if (x < x1) { srcX = (int) (x1 - x + .7f); srcWidth -= srcX; x += srcX; } if (x > x4) { srcWidth -= x - x4; } if (y < y1) { srcHeight -= y1 - y; y = y1; } if (y > y4) { srcY = (int) (y - y4); srcHeight -= srcY; y += y - y4 - srcY; } batch.draw(t, x, y, srcX, srcY, srcWidth, srcHeight); } } } if (flip) { batch.setTransformMatrix(batch.getTransformMatrix().idt()); } /* * if (debug) { batch.end(); List<Rectangle> rects = new * ArrayList<Rectangle>(); for (List<Rectangle> row : tileLayer) for * (Rectangle clip : row) rects.add(new Rectangle(clip.x, clip.y, * Math.abs(tWidth), Math.abs(tHeight))); DebugHelper.debugRectangle(new * Color(1f, 0.67f, 0f, .4f), flip ? compTransMatrix(batch, cam) : null, * rects .toArray(new Rectangle[0])); batch.begin(); } */ }
From source file:com.ridiculousRPG.animation.WeatherEffectLayer.java
License:Apache License
private Matrix4 compTransMatrix(SpriteBatch batch, Camera cam) { return batch.getTransformMatrix().translate(0, cam.viewportHeight + 2 * cam.position.y, 0).rotate(1, 0, 0, 180);/* ww w.j a v a2s . c o m*/ }
From source file:com.ridiculousRPG.event.EventObject.java
License:Apache License
public void draw(SpriteBatch spriteBatch) { if (visible) { drawDoneSwitch = true;/* ww w.j a v a 2 s . c o m*/ float eventColorBits = this.colorFloatBits; float gameColorBits = GameBase.$().getGameColorBits(); if (gameColorBits != COLOR_WHITE_BITS) { if (eventColorBits != COLOR_WHITE_BITS) { Color c1 = this.color; Color c2 = GameBase.$().getGameColorTint(); eventColorBits = Color.toFloatBits(c1.r * c2.r, c1.g * c2.g, c1.b * c2.b, c1.a * c2.a); } else { eventColorBits = gameColorBits; } } float x = drawBound.x; float y = drawBound.y; float h = drawBound.height; float w = drawBound.width; float oX = getOffsetX(); float oY = getOffsetY(); spriteBatch.setColor(eventColorBits); boolean trans = oX != 0 || oY != 0; if (trans) spriteBatch.setTransformMatrix(spriteBatch.getTransformMatrix().translate(oX, oY, 0)); if (effectRear != null) effectRear.draw(spriteBatch); if (image != null) spriteBatch.draw(image, x, y, w * .5f, h * .5f, w, h, scaleX, scaleY, rotation); if (effectFront != null) effectFront.draw(spriteBatch); if (trans) spriteBatch.setTransformMatrix(spriteBatch.getTransformMatrix().translate(-oX, -oY, 0)); spriteBatch.setColor(gameColorBits); } }
From source file:de.r2soft.empires.client.maps.sun.SolarGroup.java
License:Open Source License
public void draw(SpriteBatch batch, float parentAlpha) { batch.end();/*from w w w.java 2 s. co m*/ shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix()); shapeRenderer.setTransformMatrix(batch.getTransformMatrix()); shapeRenderer.translate(getX() / 2, getY() / 2, 0); // shapeRenderer.begin(ShapeType.Circle); shapeRenderer.circle((Gdx.graphics.getWidth() / 2) + offsetX, Gdx.graphics.getHeight() / 2, (float) system.getRadius()); shapeRenderer.circle((Gdx.graphics.getWidth() / 2) + offsetX, Gdx.graphics.getHeight() / 2, (float) (system.getRadius() + 25)); shapeRenderer.end(); batch.begin(); applyTransform(batch, computeTransform()); drawChildren(batch, parentAlpha); // switch (system.getStar().getClassification()) { // case BROWNDWARF: // batch.draw(Assets.STARS_BROWN_DWARF, Find.getCenter().x - (Values.SIZE_CELESTIAL_BROWN_DWARF // / 2) + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_BROWN_DWARF / 2), 0, 0, Values.SIZE_CELESTIAL_BROWN_DWARF, // Values.SIZE_CELESTIAL_BROWN_DWARF, 1, 1, 0); // break; // // case BLUEGIANT: // batch.draw(Assets.STARS_BLUE_GIANT, Find.getCenter().x - (Values.SIZE_CELESTIAL_BLUE_GIANT / // 2) + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_BLUE_GIANT / 2), 0, 0, Values.SIZE_CELESTIAL_BLUE_GIANT, // Values.SIZE_CELESTIAL_BLUE_GIANT, 1, 1, 0); // break; // // case NEUTRON: // batch.draw(Assets.STARS_BLUE_DWARF, Find.getCenter().x - (Values.SIZE_CELESTIAL_BLUE_DWARF / // 2) + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_BLUE_DWARF / 2), 0, 0, Values.SIZE_CELESTIAL_BLUE_DWARF, // Values.SIZE_CELESTIAL_BLUE_DWARF, 1, 1, 0); // break; // // case REDDWARF: // batch.draw(Assets.STARS_RED_DWARF, Find.getCenter().x - (Values.SIZE_CELESTIAL_RED_DWARF / 2) // + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_RED_DWARF / 2), 0, 0, Values.SIZE_CELESTIAL_RED_DWARF, // Values.SIZE_CELESTIAL_RED_DWARF, 1, 1, 0); // break; // // case REDGIANT: // batch.draw(Assets.STARS_RED_GIANT, Find.getCenter().x - (Values.SIZE_CELESTIAL_RED_GIANT / 2) // + offsetX, Find.getCenter().y // - (Values.SIZE_CELESTIAL_RED_GIANT / 2), 0, 0, Values.SIZE_CELESTIAL_RED_GIANT, // Values.SIZE_CELESTIAL_RED_GIANT, 1, 1, 0); // break; // // default: // break; // } // DRAW END }
From source file:kyle.game.besiege.location.Location.java
License:Open Source License
public void drawText(SpriteBatch batch) { float size_factor = 1.4f; if ((this.type == LocationType.VILLAGE)) size_factor = .5f * size_factor; if ((this.type == LocationType.CASTLE)) size_factor = .7f * size_factor; Color temp = batch.getColor(); float zoom = getKingdom().getMapScreen().getCamera().zoom; zoom *= size_factor;//w ww. ja va 2s . co m // TODO do some vector calculations to make this rotate // TODO create a bunch more fonts for smoother scrolling! // TODO do this in Kingdom at the end of everything // don't draw village names at a certain point. if (!(this.type == LocationType.VILLAGE && zoom > 1.5) && !(this.type == LocationType.CASTLE && zoom > 3)) { BitmapFont font; if (zoom > 7) { font = Assets.pixel150; zoom = 7; } else if (zoom > 5) { font = Assets.pixel100; zoom = 5; } else if (zoom > 4) { font = Assets.pixel80; zoom = 4; } else if (zoom > 3) { font = Assets.pixel64; zoom = 3; } // add some fonts here for smoothness else if (zoom > 2.5) { font = Assets.pixel50; zoom = 2.5f; } else if (zoom > 2) { font = Assets.pixel40; zoom = 2f; } else if (zoom > 1.5) { font = Assets.pixel30; zoom = 1.5f; } else if (zoom > 1.2) { font = Assets.pixel24; zoom = 1.2f; } else if (zoom > 1) { font = Assets.pixel20; zoom = 1f; } else if (zoom > .75) { font = Assets.pixel15; zoom = .75f; } else { font = Assets.pixel12; zoom = .6f; } String toDraw = getName(); Matrix4 mx4Font = new Matrix4(); mx4Font.trn((getX() - (int) (4.3 * toDraw.length()) * zoom), (getY() - 5 - 5 * zoom), 0); mx4Font.setToRotation(new Vector3(0, 0, 1), getKingdom().getMapScreen().getRotation()); Matrix4 tempMatrix = batch.getTransformMatrix(); batch.setTransformMatrix(mx4Font); // // draw crest Color clear_white = new Color(); clear_white.b = 1; clear_white.r = 1; clear_white.g = 1; clear_white.a = .8f; // batch.setColor(clear_white); // batch.draw(this.getFaction().crest, getCenterX() - 14*zoom, getCenterY() + 13, 30*zoom, 45*zoom); // batch.setColor(temp); // draw text font.setColor(clear_white); font.draw(batch, toDraw, getX() - (int) (4.3 * toDraw.length()) * zoom, getY() - 5 - 5 * zoom); batch.setTransformMatrix(tempMatrix); } }
From source file:nl.basroding.explorer.scenes.gamescene.RocketActor.java
@Override public void draw(SpriteBatch batch, float parentAlpha) { super.draw(batch, parentAlpha); batch.end();//from w w w . j a v a2 s.c om shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix()); shapeRenderer.setTransformMatrix(batch.getTransformMatrix()); shapeRenderer.setColor(1, 0, 0, 1); shapeRenderer.circle(rocket.getPosition().x, rocket.getPosition().y, 200); shapeRenderer.end(); batch.begin(); }