final StructShapeCommand popShapeCommandCell() { if(currShapePos >= shapeCommandQueues.size) { return null; } stackCommand.clear(); stackCommand.drawType = (DrawType) shapeCommandQueues.get(currShapePos++); stackCommand.color = (Color) shapeCommandQueues.get(currShapePos++); // 如果color是null则使用默认颜色 if(stackCommand.color == null) { stackCommand.color = getDisplayedColor(); } stackCommand.shapeType = (ShapeType) shapeCommandQueues.get(currShapePos++); stackCommand.borderWidth = (float) shapeCommandQueues.get(currShapePos++); int dataLen = (int) shapeCommandQueues.get(currShapePos++); for(int i = 0; i < dataLen; ++i) { stackCommand.vertexArray.add((Float) shapeCommandQueues.get(currShapePos++)); } return stackCommand; }
public void draw(SpriteBatch spriteBatch) { // Draw HUD Element if it needs to be drawn if (showHUDElement) { shapeRenderer.begin(ShapeType.Filled); // Change HP color to yellow between 20% and 10% and red at 10% and lower if (healthLeft >= (totalHealth * 0.4)) { healthBarColor = Color.GREEN; } else if (healthLeft < (totalHealth * 0.4) && healthLeft > (totalHealth * 0.2)) { healthBarColor = Color.YELLOW; } else if (healthLeft < (totalHealth * 0.2)) { healthBarColor = Color.RED; } shapeRenderer.setColor(healthBarColor); shapeRenderer.rect(x, y, healthLeft - 1, height); shapeRenderer.end(); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(Color.WHITE); shapeRenderer.rect(x, y, width, height); shapeRenderer.end(); } }
/** * Internal method. * * <p>Implements drawing the outline of an open and * closed polygon outline.</p> * * @see #drawPolygon(float, float...) * @see #drawOpenPolygon(float, float...) */ private void drawPolygonOutline(float lineThickness, boolean close, float... points) { if (points.length < 6) { return; // Won't draw anything; does not have at least 3 edges. } if (points.length % 2 != 0) { throw new IllegalArgumentException("uneven point"); } this.startDrawingShape(); if (renderer.getCurrentType() != ShapeType.Filled) { renderer.set(ShapeType.Filled); } for (int i = 2; i < points.length; i++) { if (i % 2 == 0) { this.drawLine(points[i - 2], points[i - 1], points[i], points[i + 1], lineThickness); } } if (close) this.drawLine(points[points.length - 2], points[points.length - 1], points[0], points[1], lineThickness); }
/** * Draws the selection rectangle using the supplied renderer if selection is * currently in progress. * * @param renderer */ private void renderSelectionRectangle() { Rectangle selection = gameState.getPlayerCharacterController() .getSelectionRectangle(); if (selection != null && Math.abs(selection.getHeight()) > Configuration .getSelectionTolerance() && Math.abs(selection.getWidth()) > Configuration .getSelectionTolerance()) { // need to call the setter to make sure the matrix gets marked as dirty shapeRenderer.setProjectionMatrix(shapeRenderer .getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(Color.GREEN); shapeRenderer.rect(selection.x, selection.y, selection.width, selection.height); shapeRenderer.end(); } }
private void renderGrid() { shapeRenderer.setColor(Color.PINK); shapeRenderer.begin(ShapeType.Line); int halfArea = 200; float width = viewport.getWorldWidth(); float height = viewport.getWorldHeight(); shapeRenderer.line(-width * halfArea, 0.0f, width * halfArea, 0.0f); shapeRenderer.line(0.0f, -height * halfArea, 0.0f, height * halfArea); shapeRenderer.setColor(Color.WHITE); for (int i = -halfArea; i < halfArea; ++i) { if (i == 0) continue; shapeRenderer.line(-width * halfArea, i, width * halfArea, i); shapeRenderer.line(i, -height * halfArea, i, height * halfArea); } shapeRenderer.end(); }
private void renderCameraDebug() { shapeRenderer.setProjectionMatrix(viewport.getCamera().combined); shapeRenderer.setColor(Color.YELLOW); shapeRenderer.begin(ShapeType.Line); shapeRenderer.rect( cameraFocusRect.x, cameraFocusRect.y, cameraFocusRect.width, cameraFocusRect.height ); shapeRenderer.setColor(Color.RED); shapeRenderer.rect( cameraTarget.x - 0.05f, cameraTarget.y - 0.05f, 0.1f, 0.1f ); shapeRenderer.end(); }
@Override public void draw() { super.draw(); if(boss != null) { renderer.begin(); moonImpactMeter.draw(renderer); renderer.end(); } if(isStageClear()) { Gdx.gl.glEnable(GL20.GL_BLEND); renderer.begin(ShapeType.Filled); renderer.setColor(screenFadeActor.getColor()); renderer.rect(screenFadeActor.getX(), screenFadeActor.getY(), screenFadeActor.getWidth(), screenFadeActor.getHeight()); renderer.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } if(debug) { uiBatch.begin(); font.draw(uiBatch, screenLogger.toString(), 50, 300); screenLogger.setLength(0); uiBatch.end(); } }
public void draw(SpriteBatch batch) { renderer.setAutoShapeType(true); renderer.begin(); renderer.setColor(Color.WHITE); for (int i = 0; i < map.length; i++) { for (int j = map[0].length - 1; j >= 0; j--) { renderer.set(filled[i][j] ? ShapeType.Filled : ShapeType.Line); renderer.setColor(filled[i][j] ? Color.WHITE : Color.GRAY); renderer.rect(i * sz + 50, j * sz + 50, sz, sz); } } renderer.set(ShapeType.Filled); renderer.setColor(Color.GREEN); renderer.rect(entrance.x * sz + 50, entrance.y * sz + 50, sz, sz); renderer.setColor(Color.YELLOW); renderer.rect(exit.x * sz + 50, exit.y * sz + 50, sz, sz); renderer.end(); }
public void render(ShapeRenderer renderer) { renderer.setColor(Constants.PLAYER_COLOR); renderer.set(ShapeType.Filled); renderer.circle(position.x, position.y, Constants.PLAYER_HEAD_RADIUS, Constants.PLAYER_HEAD_SEGMENTS); Vector2 torsoTop = new Vector2(position.x, position.y - Constants.PLAYER_HEAD_RADIUS); Vector2 torsoBottom = new Vector2(torsoTop.x, torsoTop.y - 2 * Constants.PLAYER_HEAD_RADIUS); renderer.rectLine(torsoTop, torsoBottom, Constants.PLAYER_LIMB_WIDTH); renderer.rectLine( torsoTop.x, torsoTop.y, torsoTop.x + Constants.PLAYER_HEAD_RADIUS, torsoTop.y - Constants.PLAYER_HEAD_RADIUS, Constants.PLAYER_LIMB_WIDTH); renderer.rectLine( torsoTop.x, torsoTop.y, torsoTop.x - Constants.PLAYER_HEAD_RADIUS, torsoTop.y - Constants.PLAYER_HEAD_RADIUS, Constants.PLAYER_LIMB_WIDTH); renderer.rectLine( torsoBottom.x, torsoBottom.y, torsoBottom.x + Constants.PLAYER_HEAD_RADIUS, torsoBottom.y - Constants.PLAYER_HEAD_RADIUS, Constants.PLAYER_LIMB_WIDTH); renderer.rectLine( torsoBottom.x, torsoBottom.y, torsoBottom.x - Constants.PLAYER_HEAD_RADIUS, torsoBottom.y - Constants.PLAYER_HEAD_RADIUS, Constants.PLAYER_LIMB_WIDTH); }
public void renderPlayerData() { game.spriteBatch.begin(); game.scoreFont.setColor(Color.WHITE); game.scoreFont.draw(game.spriteBatch, "Score: " + Data.SCORE, 600, 500); game.scoreFont.draw(game.spriteBatch, "Coins collected: " + Data.COINS_COLLECTED, 450, 500); game.spriteBatch.end(); game.healthBar.setAutoShapeType(true); game.healthBar.begin(); game.healthBar.set(ShapeType.Filled); game.healthBar.setColor(Color.WHITE); game.healthBar.rect(90, 465, 210, 40); game.healthBar.setColor(Color.RED); game.healthBar.rect(100, 470, Life.health * 2, 30); game.healthBar.end(); }
@Override public void render(float delta) { Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); game.spriteBatch.begin(); game.scoreFont.setColor(Color.WHITE); game.scoreFont.draw(game.spriteBatch, "Player Name (Touch to Change)", 50, 320); game.scoreFont.draw(game.spriteBatch, "Music Settings (Touch to Change)", 50, 370); game.spriteBatch.end(); game.healthBar.setAutoShapeType(true); game.healthBar.begin(); game.healthBar.setColor(Color.RED); game.healthBar.set(ShapeType.Filled); game.healthBar.rect(280, 300, 150, 30); game.healthBar.rect(280, 350, 150, 30); game.healthBar.end(); act(delta); draw(); }
@Override public void render(float delta) { // TODO: Update Icicles icicles.update(delta); player.update(delta); iciclesViewport.apply(true); Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.setProjectionMatrix(iciclesViewport.getCamera().combined); renderer.begin(ShapeType.Filled); // TODO: Render Icicles icicles.render(renderer); player.render(renderer); renderer.end(); }
@Override public void render(float delta) { // TODO: Call update() on player iciclesViewport.apply(true); Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.setProjectionMatrix(iciclesViewport.getCamera().combined); renderer.begin(ShapeType.Filled); renderer.setColor(Constants.ICICLE_COLOR); icicle.render(renderer); player.render(renderer); renderer.end(); }
@Override public void render(float delta) { // TODO: Apply the viewport iciclesViewport.apply(true); // TODO: Clear the screen to the background color Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // TODO: Set the ShapeRenderer's projection matrix renderer.setProjectionMatrix(iciclesViewport.getCamera().combined); // TODO: Draw the Icicle renderer.begin(ShapeType.Filled); icicle.render(renderer); renderer.end(); }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.begin(ShapeType.Filled); // Head renderer.circle(100, 100, 10); renderer.end(); renderer.begin(ShapeType.Line); // Torso renderer.line(100, 50, 100, 100); // Legs renderer.line(85, 35, 100, 50); renderer.line(115, 35, 100, 50); // Arms renderer.line(85, 70, 100, 85); renderer.line(115, 70, 100, 85); renderer.end(); }
/** * We'll often want to break up our drawing into separate functions, or different objects * entirely. This is easy to do, all we need to do is pass in our ShapeRenderer. */ @Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // TODO: Apply the viewport viewport.apply(); // TODO: Set the ShapeRender's projection matrix renderer.setProjectionMatrix(viewport.getCamera().combined); // TODO: Start a Filled batch renderer.begin(ShapeType.Filled); // TODO: Call drawSmileyFace() drawSmileyFace(renderer); // TODO: End the batch renderer.end(); }
private void renderParticles() { if (AppUtil.player == null) { return; } CPhysics playerPhys = pm.get(AppUtil.player); particleRenderer.setProjectionMatrix(camera.combined); particleRenderer.begin(ShapeType.Filled); for (int i = 0; i < entities.size(); i++) { CParticle particle = pam.get(entities.get(i)); if (particle == null) { continue; } particleRenderer.setColor(particle.getColor()); particleRenderer.rect(particle.getPosition().x - particle.getSize().x / 2 + getCameraOffset(playerPhys).x, particle.getPosition().y - particle.getSize().y / 2 + getCameraOffset(playerPhys).y, particle.getSize().x, particle.getSize().y); } particleRenderer.end(); }
@Override public void update (float deltaTime) { //Sets the drawn entities counter to 0 for logging purposes drawnEntities = 0; currentLayer = 0; batch.setProjectionMatrix(cameraSystem.getParalaxCamera(currentLayer).combined); batch.begin(); shapeRenderer.setProjectionMatrix(cameraSystem.getCamera().combined); shapeRenderer.begin(ShapeType.Filled); super.update(deltaTime); batch.end(); shapeRenderer.end(); //Displays the amount of entities that are being drawn // Gdx.app.debug(TAG, "drawn entities: " + drawnEntities); }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); shapeRenderer.begin(ShapeType.Filled); shapeRenderer.setColor(Color.GREEN); // Draw the stem shapeRenderer.rectLine(100, 0, 100, 300, 20); // TODO: Draw two leaves on the stem using rotated rectangles shapeRenderer.rect(100, 100, 0, 0, 40, 40, 1, 1, 135); shapeRenderer.rect(100, 150, 0, 0, 30, 30, 1, 1, 315); // TODO: Set the active color to yellow shapeRenderer.setColor(Color.YELLOW); // TODO: Use a loop to draw 20 of these petals in a circle final int petals = 20; for (int petal = 0; petal < petals; petal++) { shapeRenderer.rect(100, 300, 0, 0, 40, 40, 1, 1, 360.0f * petal / petals); } shapeRenderer.end(); }
public void DrawCollisionRectangles(SpriteBatch sb) { boolean hadToStart = false; ShapeRenderer rend = new ShapeRenderer(); if(!sb.isDrawing()) {sb.begin(); hadToStart = true;} rend.begin(ShapeType.Filled); rend.setProjectionMatrix(GlobalVariables.maincamera.combined); for(int x = 0; x < map.length; x++) { for(int y = 0; y < map[x].length; y++) { rend.rect(map[x][y].getX() * 32, map[x][y].getY() * 32, 32, 32); } } rend.end(); if(hadToStart) sb.end(); }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // TODO: Call update() on the camera // TODO: Set the SceneRenderer's projection matrix equal to the camera's combined matrix renderer.begin(ShapeType.Filled); float interval = TimeUtils.timeSinceMillis(timeCreated); float x = X_CENTER + X_AMPLITUDE * MathUtils.sin(MathUtils.PI2 * interval /PERIOD); float y = Y_CENTER + Y_AMPLITUDE * MathUtils.sin(2* MathUtils.PI2 * interval / PERIOD); renderer.circle(x, y, BALL_RADIUS); renderer.end(); }
@Override public void render(float delta) { player.update(delta); iciclesViewport.apply(true); Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.setProjectionMatrix(iciclesViewport.getCamera().combined); renderer.begin(ShapeType.Filled); renderer.setColor(Constants.ICICLE_COLOR); icicle.render(renderer); player.render(renderer); renderer.end(); }
private void drawRectFrame() { final float lineHeight = height; final float lineWidth = width + lineWeight; sr.begin(ShapeType.Filled); sr.setColor(Color.WHITE); // Left sr.rect(x, y, lineWeight, lineWeight - lineHeight); // Right sr.rect(x + width, y, lineWeight, lineWeight - lineHeight); // Top sr.rect(x, y, lineWidth, lineWeight); // Bottom sr.rect(x, y - lineHeight, lineWidth, lineWeight); sr.end(); }
public void draw(ShapeRenderer shapeRenderer) { ShapeType previousType = shapeRenderer.getCurrentType(); shapeRenderer.set(ShapeType.Filled); if (currentRadius > 0) { shapeRenderer.setColor(targetManager.currentTheme.target); shapeRenderer.circle(centerPosition.x , centerPosition.y, getRadius()); } if (dying) { shapeRenderer.setColor(targetManager.currentTheme.background); // Background color shapeRenderer.circle(centerPosition.x , centerPosition.y , currentDyingRadius); } shapeRenderer.set(previousType); }
@Override public void render(float delta) { // TODO: Call update() on player player.update(delta); iciclesViewport.apply(true); Gdx.gl.glClearColor(Constants.BACKGROUND_COLOR.r, Constants.BACKGROUND_COLOR.g, Constants.BACKGROUND_COLOR.b, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.setProjectionMatrix(iciclesViewport.getCamera().combined); renderer.begin(ShapeType.Filled); renderer.setColor(Constants.ICICLE_COLOR); icicle.render(renderer); player.render(renderer); renderer.end(); }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // TODO: Apply the viewport // TODO: Set the projection matrix of the ShapeRenderer to the combined matrix of the viewport's camera renderer.begin(ShapeType.Filled); renderer.setColor(Color.WHITE); renderer.rect(0, 0, WORLD_WIDTH, WORLD_HEIGHT); renderer.setColor(Color.BLACK); punchCantorGasket(0, 0, WORLD_WIDTH, WORLD_HEIGHT, RECURSIONS); renderer.setColor(Color.WHITE); renderer.circle(WORLD_WIDTH / 2, WORLD_HEIGHT / 2, Math.min(WORLD_WIDTH, WORLD_HEIGHT) / 6.5f, 20); renderer.end(); }
@Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // TODO: Call update() on the camera camera.update(); // TODO: Set the SceneRenderer's projection matrix equal to the camera's combined matrix renderer.setProjectionMatrix(camera.combined); renderer.begin(ShapeType.Filled); float interval = TimeUtils.timeSinceMillis(timeCreated); float x = X_CENTER + X_AMPLITUDE * MathUtils.sin(MathUtils.PI2 * interval /PERIOD); float y = Y_CENTER + Y_AMPLITUDE * MathUtils.sin(2* MathUtils.PI2 * interval / PERIOD); renderer.circle(x, y, BALL_RADIUS); renderer.end(); }
@Override public void render() { // As always, first we clear the screen Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Then we start our shapeRenderer batch, this time with ShapeType.Line shapeRenderer.begin(ShapeType.Line); // A Simple white line shapeRenderer.setColor(Color.WHITE); shapeRenderer.line(0, 0, 100, 100); // We can set different colors using two methods. We can use constants like so. shapeRenderer.setColor(Color.MAGENTA); shapeRenderer.line(10, 0, 110, 100); // We can also set a color using RGBA values shapeRenderer.setColor(0, 1, 0, 1); shapeRenderer.line(20, 0, 120, 100); // We can also do fancy things like gradients shapeRenderer.line(30, 0, 130, 100, Color.BLUE, Color.RED); // The last interesting thing we can do is draw a bunch of connected line segments using polyline // First we set up the list of vertices, where the even positions are x coordinates, and the odd positions are the y coordinates float[] verticies = {100, 200, 300, 300, 200, 300, 300, 200}; shapeRenderer.polyline(verticies); // Finally, as always, we end the batch shapeRenderer.end(); }
public void drawRect(float fromX, float fromY, float toX, float toY, Color color) { if(!batchCommand) { clear(); } pushShapeCommandCell(DrawType.Rect, color, ShapeType.Line, lineWidth, fromX, fromY, toX, toY); }