private void drawCullingRectangles(ShapeRenderer shapeRenderer, Color color) { for (BoundingBox br : boundingBoxes) { Rectangle r = br.rectangle; Rectangle cullingArea = getCullingArea(tmpRectangle, r, angleRad, position, scale); shapeRenderer.set(ShapeRenderer.ShapeType.Filled); Color fillColor = tmpColor.set(color); fillColor.a *= 0.25f; shapeRenderer.setColor(fillColor); shapeRenderer.rect(cullingArea.x, cullingArea.y, cullingArea.width, cullingArea.height); tmp.set(r.x, r.y).rotateRad(angleRad).add(position); tmp1.set(r.x + r.width, r.y).rotateRad(angleRad).add(position); tmp2.set(r.x + r.width, r.y + r.height).rotateRad(angleRad).add(position); tmp3.set(r.x, r.y + r.height).rotateRad(angleRad).add(position); shapeRenderer.set(ShapeRenderer.ShapeType.Line); shapeRenderer.setColor(color); shapeRenderer.line(tmp, tmp1); shapeRenderer.line(tmp1, tmp2); shapeRenderer.line(tmp2, tmp3); shapeRenderer.line(tmp3, tmp); } }
@Override public void render() { gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.setProjectionMatrix(worldCamera.projection); spriteBatch.setTransformMatrix(worldCamera.view); spriteBatch.begin(); farmSprite.draw(spriteBatch); spriteBatch.end(); shapeRenderer.setProjectionMatrix(worldCamera.projection); shapeRenderer.setTransformMatrix(worldCamera.view); shapeRenderer.setColor(1f, 1f, 1f, 1f); shapeRenderer.begin(ShapeType.Line); for (int i = 0; i < convexHull2d.getPointsCount(); i++) { float x0 = convexHull2d.getX(i); float y0 = convexHull2d.getY(i); if (i + 1 == convexHull2d.getPointsCount()) { float x1 = convexHull2d.getX(0); float y1 = convexHull2d.getY(0); shapeRenderer.line(x0, y0, x1, y1); break; } float x1 = convexHull2d.getX(i + 1); float y1 = convexHull2d.getY(i + 1); shapeRenderer.line(x0, y0, x1, y1); } shapeRenderer.end(); shapeRenderer.setColor(0f, 1f, 1f, 1f); shapeRenderer.begin(ShapeType.Line); for (int i = 0; i < smallConvexHull2d.getPointsCount(); i++) { float x0 = smallConvexHull2d.getX(i); float y0 = smallConvexHull2d.getY(i); if (i + 1 == smallConvexHull2d.getPointsCount()) { float x1 = smallConvexHull2d.getX(0); float y1 = smallConvexHull2d.getY(0); shapeRenderer.line(x0, y0, x1, y1); break; } float x1 = smallConvexHull2d.getX(i + 1); float y1 = smallConvexHull2d.getY(i + 1); shapeRenderer.line(x0, y0, x1, y1); } shapeRenderer.end(); shapeRenderer.setColor(1f, 0f, 0f, 1f); shapeRenderer.begin(ShapeType.FilledCircle); for (int i = 0; i < convexHull2d.getPointsCount(); i++) { float x = convexHull2d.getX(i); float y = convexHull2d.getY(i); shapeRenderer.filledCircle(x, y, 1f, 5); } shapeRenderer.end(); }
private void render_game_background() { shapeCreator.begin(ShapeType.Line); shapeCreator.setProjectionMatrix(camera.combined); shapeCreator.setColor(Color.WHITE); // Top line of user's play grid shapeCreator.line( TOP_LEFT_USER_GRID_X, TOP_LEFT_USER_GRID_Y, (float) (TOP_LEFT_USER_GRID_X + (CONSTANT.GAME_WORLD_WIDTH * (3.0 / 5.0))), TOP_LEFT_USER_GRID_Y); // Bottom line of user's play grid shapeCreator.line( TOP_LEFT_USER_GRID_X, (float) (TOP_LEFT_USER_GRID_Y - (CONSTANT.GAME_WORLD_HEIGHT * (12.0 / 35.0))), (float) (TOP_LEFT_USER_GRID_X + (CONSTANT.GAME_WORLD_WIDTH * (3.0 / 5.0))), (float) (TOP_LEFT_USER_GRID_Y - (CONSTANT.GAME_WORLD_HEIGHT * (12.0 / 35.0)))); // Center line of user's play grid shapeCreator.line( TOP_LEFT_USER_GRID_X, (float) (TOP_LEFT_USER_GRID_Y - (CONSTANT.GAME_WORLD_HEIGHT * (6.0 / 35.0))), (float) (TOP_LEFT_USER_GRID_X + (CONSTANT.GAME_WORLD_WIDTH * (3.0 / 5.0))), (float) (TOP_LEFT_USER_GRID_Y - (CONSTANT.GAME_WORLD_HEIGHT * (6.0 / 35.0)))); // Left Border of user's play grid for (int counter = 0; counter < 8; counter++) { shapeCreator.line( (float) (TOP_LEFT_USER_GRID_X + (counter * CONSTANT.GAME_WORLD_WIDTH * (3.0 / 35.0))), TOP_LEFT_USER_GRID_Y, (float) (TOP_LEFT_USER_GRID_X + (counter * CONSTANT.GAME_WORLD_WIDTH * (3.0 / 35.0))), (float) (TOP_LEFT_USER_GRID_Y - (CONSTANT.GAME_WORLD_HEIGHT * (12.0 / 35.0)))); if (counter < 7) { user_locations.add( new Vector2( (float) (TOP_LEFT_USER_GRID_X + (CONSTANT.GAME_WORLD_WIDTH * (1.5 / 35.0)) + (counter * CONSTANT.GAME_WORLD_WIDTH * (3.0 / 35.0))), (float) (TOP_LEFT_USER_GRID_Y + (CONSTANT.GAME_WORLD_HEIGHT * (3.0 / 35.0))))); user_locations.add( new Vector2( (float) (TOP_LEFT_USER_GRID_X + (CONSTANT.GAME_WORLD_WIDTH * (1.5 / 35.0)) + (counter * CONSTANT.GAME_WORLD_WIDTH * (3.0 / 35.0))), (float) (TOP_LEFT_USER_GRID_Y + (CONSTANT.GAME_WORLD_HEIGHT * (9.0 / 35.0))))); } } shapeCreator.end(); }
private void drawGrid() { int height = GdxController.getInstance().getMapGdx().getForeground().getHeight(); int width = GdxController.getInstance().getMapGdx().getForeground().getWidth(); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(Color.RED); for (int i = 0; i < 50; i++) { shapeRenderer.line(0.0f, i * 32.0f, width * 32.0f, i * 32.0f); shapeRenderer.line(i * 32.0f, 0.0f, i * 32.0f, height * 32.0f); } shapeRenderer.end(); }
private void drawTrajectory() { float offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT; float offsetY = Constants.WEAPON_OFFSET_FROM_PLAYER_Y; if (player.getFacing() == 0) { offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_RIGHT; } else { offsetX = Constants.WEAPON_OFFSET_FROM_PLAYER_X_FACING_LEFT; } Player p = player; Float originX = p.getX() + offsetX + Constants.WEAPON_ORIGIN_X; Float originY = p.getY() + offsetY + Constants.WEAPON_ORIGIN_Y; Float mouseX = player.getTargetX(); Float mouseY = player.getTargetY(); Float deltaX = (mouseX - originX); Float deltaY = (mouseY - originY); Double angle = Math.atan2(deltaY.doubleValue(), deltaX.doubleValue()); Float x = (float) Math.cos(angle.floatValue()); Float y = (float) Math.sin(angle.floatValue()); Float calculatedX = originX + x * Constants.SHOT_DISTANCE_FROM_ORIGIN; Float calculatedY = originY + y * Constants.SHOT_DISTANCE_FROM_ORIGIN; shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(Color.RED); shapeRenderer.line(calculatedX, calculatedY, mouseX, mouseY); shapeRenderer.end(); }
private void drawTriangleStrips(ShapeRenderer shapeRenderer, Color color, Color color1) { for (int i = 0; i < vertexDataArray.size; i++) { StripVertex bb = vertexDataArray.items[i]; Array<Float> data = bb.insideVertexData; for (int j = 0; j < data.size - 3; ) { shapeRenderer.setColor(j == 0 ? color : color1); tmp.x = data.items[j]; tmp.y = data.items[j + 1]; tmp.rotateRad(angleRad); tmp.scl(scale); tmp.add(position); tmp1.x = data.items[j + 3]; tmp1.y = data.items[j + 4]; tmp1.rotateRad(angleRad); tmp1.scl(scale); tmp1.add(position); j += 3; shapeRenderer.line(tmp, tmp1); } data = bb.outsideVertexData; for (int j = 0; j < data.size - 3; ) { shapeRenderer.setColor(j == 0 ? Color.ORANGE : Color.RED); tmp.x = data.items[j]; tmp.y = data.items[j + 1]; tmp.rotateRad(angleRad); tmp.scl(scale); tmp.add(position); tmp1.x = data.items[j + 3]; tmp1.y = data.items[j + 4]; tmp1.rotateRad(angleRad); tmp1.scl(scale); tmp1.add(position); j += 3; shapeRenderer.line(tmp, tmp1); } } }
@Override public void render(final float deltaTime) { // Sets the clear color Gdx.gl.glClearColor(0, 0, 0, 1); // Clears the screen Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // Gets the x position of the camera, clamping it if out of bounds camera.position.x = MathUtils.clamp( worldManager.player.getPosition().x, camera.viewportWidth / 2f, worldManager.mapWidth - (camera.viewportWidth / 2f)); // Updates the camera camera.update(); // Renders the world worldManager.render(game.batch, camera, deltaTime); // Updates the input updateInput(); // Sets the world (applies the cycle's physics to the bodies) worldManager.step(deltaTime); // Renders the debugging mouse info, don't worry about it if (originVector != null) { Gdx.gl.glEnable(GL20.GL_BLEND); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.setColor(0.5f, 0.5f, 0, 0.5f); shapeRenderer.line( originVector.x - ControlListener.MIN_X_DISTANCE, 0, originVector.x - ControlListener.MIN_X_DISTANCE, Gdx.graphics.getHeight()); shapeRenderer.line( originVector.x + ControlListener.MIN_X_DISTANCE, 0, originVector.x + ControlListener.MIN_X_DISTANCE, Gdx.graphics.getHeight()); shapeRenderer.setColor(0, 0.5f, 0.5f, 0.5f); shapeRenderer.circle( originVector.x, Gdx.graphics.getHeight() - originVector.y, ControlListener.ORIGIN_MAX_DISTANCE); shapeRenderer.end(); Gdx.gl.glDisable(GL20.GL_BLEND); } }
@Override public void render(float dt) { Gdx.graphics.getGL20().glClear(GL20.GL_COLOR_BUFFER_BIT); ShapeRenderer shapeRenderer = this.gsm.game().getShapeRenderer(); shapeRenderer.setProjectionMatrix(cam.combined); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.setColor(Color.DARK_GRAY); float factor = zoom > 1 ? zoom : 1; for (int x = 0; x < V_WIDTH * factor; x += gridSize) { shapeRenderer.line(x, 0, x, height * factor); } for (int y = 0; y < V_HEIGHT * factor; y += gridSize) { shapeRenderer.line(0, y, width * factor, y); } for (Selectable shape : controller.levelObjects) { shape.render(shapeRenderer); } shapeRenderer.end(); SpriteBatch sp = this.gsm.game().getBatch(); sp.begin(); bitmapFont.draw(sp, current_Tool.name(), 20, V_HEIGHT - 20); if (current_Tool == E_TOOL.POINT) bitmapFont.draw(sp, point_Type.name(), 20, V_HEIGHT - 40); if (current_Tool == E_TOOL.RECTANGLE || current_Tool == E_TOOL.CIRCLE) bitmapFont.draw(sp, shape_Type.name(), 20, V_HEIGHT - 40); if (current_Tool == E_TOOL.SELECT && controller.selection != null) { if (controller.selection instanceof Shape) bitmapFont.draw(sp, shape_Type.name(), 20, V_HEIGHT - 40); if (controller.selection instanceof Point) bitmapFont.draw(sp, point_Type.name(), 20, V_HEIGHT - 40); } sp.end(); stage.draw(); }
private void drawRect(Actor actor, DebugRect debugRect) { topLeft.set(debugRect.bottomLeft.x, debugRect.topRight.y); topRight.set(debugRect.topRight.x, debugRect.topRight.y); bottomRight.set(debugRect.topRight.x, debugRect.bottomLeft.y); bottomLeft.set(debugRect.bottomLeft.x, debugRect.bottomLeft.y); // Transform to stage coordinates using the scale, rotation and translation of the entire // ancestor hierarchy. actor.localToStageCoordinates(topLeft); actor.localToStageCoordinates(topRight); actor.localToStageCoordinates(bottomRight); actor.localToStageCoordinates(bottomLeft); shapes.setColor(debugRect.color); shapes.line(topLeft, topRight); shapes.line(topRight, bottomRight); shapes.line(bottomRight, bottomLeft); shapes.line(bottomLeft, topLeft); }
/** * Draws an outline of a rectangle using a <code>ShapeRenderer</code>.<br> * IMPORTANT: Don't forget to set the <code>ShapeRenderer</code>'s projection matrix with {@link * #setShapeRendererProjectionMatrix(Matrix4)}! * * @param batch - Since drawing is done with a <code>ShapeRenderer</code>, the active batch should * be passed to this method to end/start it. */ public static void drawLine(SpriteBatch batch, float x1, float y1, float x2, float y2, Color c) { batch.end(); Gdx.gl.glEnable(GL20.GL_BLEND); shapes_.begin(ShapeType.Line); shapes_.setColor(c); shapes_.line(x1, y1, x2, y2); shapes_.end(); Gdx.gl.glDisable(GL20.GL_BLEND); batch.begin(); }
private static void renderNodeList(List<Vector2> nodes, ShapeRenderer renderer, Color color) { renderer.setColor(color); for (int i = 0; i < nodes.size(); i++) { Vector2 node = nodes.get(i); renderer.circle(node.x, node.y, LevelEditorScreen.getNodeRadius(), 8); if (i > 0) { Vector2 previousNode = nodes.get(i - 1); renderer.line(node.x, node.y, previousNode.x, previousNode.y); } } }
public void drawMisc(Ship ship, GameController controller) { batch.begin(); batch.draw( Textures.BOMB_TEXTURE, border + (Sizes.DEFAULT_WORLD_WIDTH - Sizes.SHOT_BOMB_WIDTH - Sizes.MISC_BOMB_INFO_OFFSET) * ppux, 0.1f * ppuy, ppux * Sizes.SHOT_BOMB_WIDTH, ppuy * Sizes.SHOT_BOMB_HEIGHT); miscTextFont.draw( batch, "x" + String.valueOf(ship.getBombs()), border + (Sizes.DEFAULT_WORLD_WIDTH - Sizes.MISC_BOMB_INFO_OFFSET) * ppux, Sizes.FONT_SIZE_MISC * ppuy); miscTextFont.draw( batch, "Level: " + controller.getLevel(), border + 1 * ppux, (Sizes.DEFAULT_WORLD_HEIGHT - Sizes.MISC_POINT_INFO_OFFSET) * ppuy); miscTextFont.draw( batch, "Points: " + controller.points, border + (Sizes.DEFAULT_WORLD_WIDTH / 2) * ppux, (Sizes.DEFAULT_WORLD_HEIGHT - Sizes.MISC_POINT_INFO_OFFSET) * ppuy); batch.end(); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(Color.WHITE); shapeRenderer.line(border, 0, border, Sizes.DEFAULT_WORLD_HEIGHT * ppuy); shapeRenderer.line( border + Sizes.DEFAULT_WORLD_WIDTH * ppux, 0, border + Sizes.DEFAULT_WORLD_WIDTH * ppux, Sizes.DEFAULT_WORLD_HEIGHT * ppuy); shapeRenderer.end(); }
protected void debugDrawWorld() { if (Env.debug) { shapeRenderer.setProjectionMatrix(camera.combined); if (Env.drawGrid) { // Debug shapes shapeRenderer.setColor(1.0f, 0.0f, 0.0f, 1.0f); shapeRenderer.begin(ShapeType.Line); shapeRenderer.line(-Env.virtualWidth * 0.5f, 0.0f, Env.virtualWidth * 0.5f, 0.0f); shapeRenderer.line(0.0f, -Env.virtualHeight * 0.5f, 0.0f, Env.virtualHeight * 0.5f); shapeRenderer.setColor(0.0f, 1.0f, 0.0f, 1.0f); for (int i = -100; i <= 100; ++i) { if (i == 0) continue; shapeRenderer.line(-Env.virtualWidth * 0.5f, i, Env.virtualWidth * 0.5f, i); } for (int i = -100; i <= 100; ++i) { if (i == 0) continue; shapeRenderer.line(i, -Env.virtualHeight * 0.5f, i, Env.virtualHeight * 0.5f); } shapeRenderer.end(); } box2DRenderer.setDrawAABBs(Env.drawABBs); box2DRenderer.setDrawBodies(Env.drawBodies); box2DRenderer.setDrawContacts(Env.drawContacts); box2DRenderer.setDrawInactiveBodies(Env.drawInactiveBodies); box2DRenderer.setDrawJoints(Env.drawJoints); box2DRenderer.setDrawVelocities(Env.drawVelocities); box2DRenderer.render(Env.game.getWorld(), camera.combined); } }
private static void renderLines(Camera camera) { shapeRenderer.setProjectionMatrix(camera.combined); shapeRenderer.begin(ShapeType.Line); Vector2 p0, p1; for (Object[] line : lines) { p0 = (Vector2) line[0]; p1 = (Vector2) line[1]; shapeRenderer.setColor(line[2] != null ? (Color) line[2] : colorLines); shapeRenderer.line(p0, p1); } lines.clear(); shapeRenderer.end(); }
private void drawLineFromFirstToLast(ShapeRenderer shapeRenderer, Color color) { shapeRenderer.setColor(color); for (BoundingBox br : boundingBoxes) { tmp.set(vertices.items[br.begin]); tmp.rotateRad(angleRad); tmp.scl(scale); tmp.add(position); tmp1.set(vertices.items[(br.begin + br.count) % vertices.size]); tmp1.rotateRad(angleRad); tmp1.scl(scale); tmp1.add(position); shapeRenderer.line(tmp, tmp1); } }
public static void drawPath(GraphPathImp path) { Iterator<Node> pathIterator = path.iterator(); Node priorNode = null; while (pathIterator.hasNext()) { Node node = pathIterator.next(); int index = node.getIndex(); shapeRenderer.setProjectionMatrix(camera.combined); shapeRenderer.begin(ShapeRenderer.ShapeType.Filled); shapeRenderer.setColor(1, 0, 0, 1); shapeRenderer.circle( LevelManager.tilePixelWidth / 2 + (index % LevelManager.lvlTileWidth) * LevelManager.tilePixelWidth, LevelManager.tilePixelHeight / 2 + (index / LevelManager.lvlTileWidth) * LevelManager.tilePixelHeight, 5); shapeRenderer.end(); if (priorNode != null) { int index2 = priorNode.getIndex(); shapeRenderer.begin(ShapeRenderer.ShapeType.Line); shapeRenderer.line( LevelManager.tilePixelWidth / 2 + (index % LevelManager.lvlTileWidth) * LevelManager.tilePixelWidth, LevelManager.tilePixelHeight / 2 + (index / LevelManager.lvlTileWidth) * LevelManager.tilePixelHeight, LevelManager.tilePixelWidth / 2 + (index2 % LevelManager.lvlTileWidth) * LevelManager.tilePixelWidth, LevelManager.tilePixelHeight / 2 + (index2 / LevelManager.lvlTileWidth) * LevelManager.tilePixelHeight); shapeRenderer.end(); } priorNode = node; } }
@Override public void render(float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); logger.log(); stage.draw(); stage.act(); stage.getRoot().getColor().a = 0f; batch.begin(); font.draw(batch, stage.getCuvant().toUpperCase(), 15, 790); font.draw(batch, totalPointsStr, 420, 790); if (stage.eCuvant()) { font.setColor(Color.GREEN); } if (drawTween) { tweenFont.draw(batch, "+" + points, tweenFont.getX(), tweenFont.getY()); } // playButton.setAlpha(0.5f); // batch.draw(playButton, 220, 750); batch.end(); // draw the line shapeRend.begin(ShapeType.Line); shapeRend.setColor(Color.ORANGE); shapeRend.line(0, 745, 480, 745); shapeRend.end(); manager.update(delta); showMenu(); }
public void drawBBoxLines(ShapeRenderer renderer) { // renderer.begin(ShapeType.Rectangle); renderer.begin(ShapeType.Line); for (BaseActor a : actors.values()) { Polygon p = a.getBBox(); if (p == null) { EngineLogger.error("ERROR DRAWING BBOX FOR: " + a.getId()); } if (a instanceof ObstacleActor) renderer.setColor(OBSTACLE_COLOR); else renderer.setColor(ACTOR_BBOX_COLOR); renderer.polygon(p.getTransformedVertices()); // Rectangle r = a.getBBox().getBoundingRectangle(); // renderer.rect(r.getX(), r.getY(), r.getWidth(), r.getHeight()); } if (polygonalNavGraph != null) { renderer.setColor(WALKZONE_COLOR); renderer.polygon(polygonalNavGraph.getWalkZone().getTransformedVertices()); // DRAW LINEs OF SIGHT renderer.setColor(Color.WHITE); ArrayList<NavNodePolygonal> nodes = polygonalNavGraph.getGraphNodes(); for (NavNodePolygonal n : nodes) { for (NavNode n2 : n.neighbors) { renderer.line(n.x, n.y, ((NavNodePolygonal) n2).x, ((NavNodePolygonal) n2).y); } } } renderer.end(); }
/** Draws a line. The {@link ShapeType} passed to begin has to be {@link ShapeType#Line}. */ public final void line(float x, float y, float z, float x2, float y2, float z2) { line(x, y, z, x2, y2, z2, color, color); }
public void render() { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); float delta = Gdx.graphics.getDeltaTime(); // Draw skeleton origin lines. ShapeRenderer shapes = debugRenderer.getShapeRenderer(); if (state != null) { shapes.setColor(Color.DARK_GRAY); shapes.begin(ShapeType.Line); shapes.line(skeleton.x, -99999, skeleton.x, 99999); shapes.line(-99999, skeleton.y, 99999, skeleton.y); shapes.end(); } if (skeleton != null) { // Reload if skeleton file was modified. if (reloadTimer <= 0) { lastModifiedCheck -= delta; if (lastModifiedCheck < 0) { lastModifiedCheck = checkModifiedInterval; long time = skeletonFile.lastModified(); if (time != 0 && lastModified != time) reloadTimer = reloadDelay; } } else { reloadTimer -= delta; if (reloadTimer <= 0) { loadSkeleton(skeletonFile); ui.toast("Reloaded."); } } // Pose and render skeleton. state.getData().setDefaultMix(ui.mixSlider.getValue()); renderer.setPremultipliedAlpha(ui.premultipliedCheckbox.isChecked()); skeleton.setFlip(ui.flipXCheckbox.isChecked(), ui.flipYCheckbox.isChecked()); skeleton.setPosition(skeletonX, skeletonY); delta = Math.min(delta, 0.032f) * ui.speedSlider.getValue(); skeleton.update(delta); state.update(delta); state.apply(skeleton); skeleton.updateWorldTransform(); batch.setColor(Color.WHITE); batch.begin(); renderer.draw(batch, skeleton); batch.end(); debugRenderer.setBones(ui.debugBonesCheckbox.isChecked()); debugRenderer.setRegionAttachments(ui.debugRegionsCheckbox.isChecked()); debugRenderer.setBoundingBoxes(ui.debugBoundingBoxesCheckbox.isChecked()); debugRenderer.setMeshHull(ui.debugMeshHullCheckbox.isChecked()); debugRenderer.setMeshTriangles(ui.debugMeshTrianglesCheckbox.isChecked()); debugRenderer.setPaths(ui.debugPathsCheckbox.isChecked()); debugRenderer.draw(skeleton); } if (state != null) { // AnimationState status. status.setLength(0); for (int i = 0, n = state.getTracks().size; i < n; i++) { TrackEntry entry = state.getTracks().get(i); if (entry == null) continue; status.append(i); status.append(": [LIGHT_GRAY]"); status(entry); status.append("[WHITE]"); status.append(entry.animation.name); status.append('\n'); } ui.statusLabel.setText(status); } // Render UI. ui.render(); // Draw indicator lines for animation and mix times. if (state != null) { TrackEntry entry = state.getCurrent(0); if (entry != null) { shapes.begin(ShapeType.Line); float percent = entry.getAnimationTime() / entry.getAnimationEnd(); float x = ui.window.getRight() + (Gdx.graphics.getWidth() - ui.window.getRight()) * percent; shapes.setColor(Color.CYAN); shapes.line(x, 0, x, 12); percent = entry.getMixDuration() == 0 ? 1 : Math.min(1, entry.getMixTime() / entry.getMixDuration()); x = ui.window.getRight() + (Gdx.graphics.getWidth() - ui.window.getRight()) * percent; shapes.setColor(Color.RED); shapes.line(x, 0, x, 12); shapes.end(); } } }
public void drawDebug(ShapeRenderer shape) { if (isHorizontal) shape.setColor(Color.RED); else shape.setColor(Color.CYAN); shape.rect(enemyRec.x, enemyRec.y, enemyRec.width, enemyRec.height); if (!isTarget) { if (game.player.isFlashLight()) { if (!isLeft) shape.line( enemyRec.x - normalRange / 2, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x + enemyRec.width + normalRange * 1.5f, enemyRec.getY() + enemyRec.getHeight() / 2); else shape.line( enemyRec.x + enemyRec.width + normalRange / 2, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x - normalRange * 1.5f, enemyRec.getY() + enemyRec.getHeight() / 2); } else { if (!isLeft) shape.line( enemyRec.x + enemyRec.width, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x + enemyRec.width + normalRange, enemyRec.getY() + enemyRec.getHeight() / 2); else shape.line( enemyRec.x, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x - normalRange, enemyRec.getY() + enemyRec.getHeight() / 2); } } else { if (game.player.isFlashLight()) { if (!isPlayerLeft) shape.line( enemyRec.x + enemyRec.width, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x + enemyRec.width + targetRange * 1.2f, enemyRec.getY() + enemyRec.getHeight() / 2); else shape.line( enemyRec.x, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x - targetRange * 1.2f, enemyRec.getY() + enemyRec.getHeight() / 2); } else { if (!isPlayerLeft) shape.line( enemyRec.x + enemyRec.width, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x + enemyRec.width + targetRange, enemyRec.getY() + enemyRec.getHeight() / 2); else shape.line( enemyRec.x, enemyRec.getY() + enemyRec.getHeight() / 2, enemyRec.x - targetRange, enemyRec.getY() + enemyRec.getHeight() / 2); } } }
/** * Draws a line in the x/y plane. The {@link ShapeType} passed to begin has to be {@link * ShapeType#Line}. */ public final void line(float x, float y, float x2, float y2) { line(x, y, 0.0f, x2, y2, 0.0f, color, color); }
@Override public void render(float delta) { // update and draw stuff Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); batch.setProjectionMatrix(camera.combined); shapes.setProjectionMatrix(camera.combined); shapes.begin(ShapeType.Line); shapes.setColor(Color.RED); for (int x = 0; x < Gdx.graphics.getWidth(); x += Constants.TILE_SIZE) { shapes.line(x, 0, x, Gdx.graphics.getHeight()); } for (int y = 0; y < Gdx.graphics.getHeight(); y += Constants.TILE_SIZE) { shapes.line(0, y, Gdx.graphics.getWidth(), y); } shapes.end(); shapes.begin(ShapeType.Filled); shapes.setColor(Color.CYAN); for (Entity entity : allEntities) { if (entity != null) { for (BoundingShape b : entity.getBoundingShapes()) { Rectangle2D bounds = b.getShape().getBounds2D(); shapes.rect( (float) bounds.getX() + entity.getX(), (float) bounds.getY() + entity.getY(), (float) bounds.getWidth(), (float) bounds.getHeight()); } } } shapes.setColor(Color.GREEN); for (int x = 0; x < staticGrid.length; x++) { for (int y = 0; y < staticGrid[0].length; y++) { if (staticGrid[x][y] == 1) shapes.rect( x * Constants.TILE_SIZE, y * Constants.TILE_SIZE, Constants.TILE_SIZE, Constants.TILE_SIZE); } } shapes.end(); batch.begin(); for (Entity entity : allEntities) { if (entity != null) { if (entity.getSprite() != null) { batch.draw(entity.getSprite(), entity.getX(), entity.getY()); } } } // batch.draw(player.getSprite(), player.getSprite().getX(), // player.getSprite().getY(),player.getSprite().getOriginX(), // player.getSprite().getOriginY(), // // player.getSprite().getWidth(),player.getSprite().getHeight(),player.getSprite().getScaleX(),player. // getSprite().getScaleY(),player.getSprite().getRotation()); batch.end(); batch.begin(); font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 50, 50); font.draw(batch, "Mouse X: " + Gdx.input.getX(), 50, 80); font.draw(batch, "Mouse Y: " + Gdx.input.getY(), 50, 110); batch.end(); // debugRenderer.render(world, debugMatrix); for (Entity entity : allEntities) { if (entity != null) { entity.update(delta); // update all entities before handling collisions } } updateQuad(); ArrayList<BoundingShape> returnObjects = new ArrayList<BoundingShape>(); for (Entity entity : allEntities) { if (entity != null) { ArrayList<BoundingShape> bs = entity.getBoundingShapes(); for (int j = 0; j < bs.size(); j++) { returnObjects.clear(); BoundingShape currentBounding = bs.get(j); quad.retrieve(returnObjects, currentBounding); for (int x = 0; x < returnObjects.size(); x++) { // Run collision detection algorithm between objects BoundingShape other = returnObjects.get(x); // System.out.println(other.getUserData()); if (currentBounding.intersects(other)) { if (currentBounding.getOwner() != other.getOwner()) { currentBounding .getOwner() .collide( new Collision( currentBounding.getOwner(), other.getOwner(), currentBounding, other)); // System.out.println("Collision: " + currentBounding.getUserData() + " + " + // other.getUserData()); } } } } entity.postCollisionUpdate(); } } }
/** * Draws a line. The {@link ShapeType} passed to begin has to be {@link ShapeType#Line}. Lazy * method that "just" calls the "other" method and unpacks the Vector2 for you */ public final void line(Vector2 v0, Vector2 v1) { line(v0.x, v0.y, 0.0f, v1.x, v1.y, 0.0f, color, color); }
/** Draws two crossed lines. */ public void x(float x, float y, float radius) { if (currType != ShapeType.Line) throw new GdxRuntimeException("Must call begin(ShapeType.Line)"); line(x - radius, y - radius, x + radius, y + radius); line(x - radius, y + radius, x + radius, y - radius); }
/** * Draws a line in the x/y plane. The {@link ShapeType} passed to begin has to be {@link * ShapeType#Line}. The line is drawn with 2 colors interpolated between start & end point. * * @param c1 Color at start of the line * @param c2 Color at end of the line */ public final void line(float x, float y, float x2, float y2, Color c1, Color c2) { line(x, y, 0.0f, x2, y2, 0.0f, c1, c2); }
/** * Draws a line. The {@link ShapeType} passed to begin has to be {@link ShapeType#Line}. Lazy * method that "just" calls the "other" method and unpacks the Vector3 for you */ public final void line(Vector3 v0, Vector3 v1) { line(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, color, color); }
@Override public void render() { long timeToRun = (long) (sliderMillisAvailablePerFrame.getValue() * 1000000f); scheduler.run(timeToRun); renderer.begin(ShapeType.Filled); int level = 0; worldMap.setLevel(level); int xMax = HierarchicalTiledGraph.sizeX[level]; int yMax = HierarchicalTiledGraph.sizeY[level]; for (int x = 0; x < xMax; x++) { for (int y = 0; y < yMax; y++) { switch (worldMap.getNode(x, y).type) { case TiledNode.TILE_FLOOR: renderer.setColor(Color.WHITE); break; case TiledNode.TILE_WALL: renderer.setColor(Color.GRAY); break; default: renderer.setColor(Color.BLACK); break; } renderer.rect(x * width, y * width, width, width); } } // Draw path nodes for (int p = 0; p < numPaths; p++) { TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[p]; int nodeCount = path.getCount(); if (nodeCount == 0) break; renderer.setColor(p % 2 == 0 ? Color.RED : Color.ORANGE); for (int i = 0; i < nodeCount; i++) { HierarchicalTiledNode node = path.nodes.get(i); renderer.rect(node.x * width, node.y * width, width, width); } } if (smooth) { renderer.end(); renderer.begin(ShapeType.Line); // Draw lines between path nodes for (int p = 0; p < numPaths; p++) { TiledSmoothableGraphPath<HierarchicalTiledNode> path = paths[p]; int nodeCount = path.getCount(); if (nodeCount > 0) { float hw = width / 2f; HierarchicalTiledNode prevNode = path.nodes.get(0); renderer.setColor(p % 2 == 0 ? Color.RED : Color.ORANGE); for (int i = 1; i < nodeCount; i++) { HierarchicalTiledNode node = path.nodes.get(i); renderer.line( node.x * width + hw, node.y * width + hw, prevNode.x * width + hw, prevNode.y * width + hw); prevNode = node; } } } } // Draw the lower level node of the buildings (usually a tile close to the center of mass) level = 1; worldMap.setLevel(level); xMax = HierarchicalTiledGraph.sizeX[level]; yMax = HierarchicalTiledGraph.sizeY[level]; renderer.end(); renderer.begin(ShapeType.Line); renderer.setColor(Color.MAROON); float hw = width * .5f; for (int x = 0; x < xMax; x++) { for (int y = 0; y < yMax; y++) { HierarchicalTiledNode lln = worldMap.getNode(x, y).getLowerLevelNode(); renderer.circle(lln.x * width + hw, lln.y * width + hw, hw); } } renderer.end(); }