Java Code Examples for org.newdawn.slick.Graphics#rotate()
The following examples show how to use
org.newdawn.slick.Graphics#rotate() .
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: RotateTransition.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException { g.translate(container.getWidth()/2, container.getHeight()/2); g.scale(scale,scale); g.rotate(0, 0, ang); g.translate(-container.getWidth()/2, -container.getHeight()/2); if (background != null) { Color c = g.getColor(); g.setColor(background); g.fillRect(0,0,container.getWidth(),container.getHeight()); g.setColor(c); } prev.render(container, game, g); g.translate(container.getWidth()/2, container.getHeight()/2); g.rotate(0, 0, -ang); g.scale(1/scale,1/scale); g.translate(-container.getWidth()/2, -container.getHeight()/2); }
Example 2
Source File: GradientTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.rotate(400, 300, ang); g.fill(rect, gradient); g.fill(round, gradient); g.fill(poly, gradient2); g.fill(center, gradient4); g.setAntiAlias(true); g.setLineWidth(10); g.draw(round2, gradient2); g.setLineWidth(2); g.draw(poly, gradient); g.setAntiAlias(false); g.fill(center, gradient4); g.setAntiAlias(true); g.setColor(Color.black); g.draw(center); g.setAntiAlias(false); }
Example 3
Source File: GradientImageTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.drawString("R - Toggle Rotationg",10,50); g.drawImage(image1, 100, 236); g.drawImage(image2, 600, 236); g.translate(0, -150); g.rotate(400, 300, ang); g.texture(shape, image2); g.texture(shape, image1, fill); g.resetTransform(); g.translate(0, 150); g.rotate(400, 300, ang); g.texture(poly, image2); g.texture(poly, image1, fill); g.resetTransform(); }
Example 4
Source File: CanvasContainerTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { image.draw(0,0); image.draw(500,0,200,100); scaleMe.draw(500,100,200,100); scaled.draw(400,500); Image flipped = scaled.getFlippedCopy(true, false); flipped.draw(520,500); Image flipped2 = flipped.getFlippedCopy(false, true); flipped2.draw(520,380); Image flipped3 = flipped2.getFlippedCopy(true, false); flipped3.draw(400,380); for (int i=0;i<3;i++) { subImage.draw(200+(i*30),300); } g.translate(500, 200); g.rotate(50, 50, rot); g.scale(0.3f,0.3f); image.draw(); g.resetTransform(); }
Example 5
Source File: TestState2.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics) */ public void render(GameContainer container, StateBasedGame game, Graphics g) { g.setFont(font); g.setColor(Color.green); g.drawString("This is State 2", 200, 50); g.rotate(400,300,ang); g.drawImage(image,400-(image.getWidth()/2),300-(image.getHeight()/2)); }
Example 6
Source File: PackedSheetTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { rocket.draw((int) r,100); runner.draw(250,250); g.scale(1.2f,1.2f); runner.draw(250,250); g.scale(1.2f,1.2f); runner.draw(250,250); g.resetTransform(); g.rotate(670, 470, ang); sheet.getSprite("floppy").draw(600,400); }
Example 7
Source File: ImageTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { g.drawRect(0,0,image.getWidth(),image.getHeight()); image.draw(0,0); image.draw(500,0,200,100); scaleMe.draw(500,100,200,100); scaled.draw(400,500); Image flipped = scaled.getFlippedCopy(true, false); flipped.draw(520,500); Image flipped2 = flipped.getFlippedCopy(false, true); flipped2.draw(520,380); Image flipped3 = flipped2.getFlippedCopy(true, false); flipped3.draw(400,380); for (int i=0;i<3;i++) { subImage.draw(200+(i*30),300); } g.translate(500, 200); g.rotate(50, 50, rot); g.scale(0.3f,0.3f); image.draw(); g.resetTransform(); rotImage.setRotation(rot); rotImage.draw(100, 200); }
Example 8
Source File: BigImageTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) { original.draw(0,0,new Color(1,1,1,0.4f)); image.draw(x,y); imageX.draw(x+400,y); imageY.draw(x,y+300); scaledSub.draw(x+300,y+300); bigSheet.getSprite(7, 5).draw(50,10); g.setColor(Color.white); g.drawRect(50,10,64,64); g.rotate(x+400, y+165, ang); g.drawImage(sub, x+300, y+100); }
Example 9
Source File: ClipTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.white); g.drawString("1 - No Clipping", 100, 10); g.drawString("2 - Screen Clipping", 100, 30); g.drawString("3 - World Clipping", 100, 50); if (world) { g.drawString("WORLD CLIPPING ENABLED", 200, 80); } if (clip) { g.drawString("SCREEN CLIPPING ENABLED", 200, 80); } g.rotate(400, 400, ang); if (world) { g.setWorldClip(350,302,100,196); } if (clip) { g.setClip(350,302,100,196); } g.setColor(Color.red); g.fillOval(300,300,200,200); g.setColor(Color.blue); g.fillRect(390,200,20,400); g.clearClip(); g.clearWorldClip(); }
Example 10
Source File: Scroller.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Draw a single tank to the game * * @param g The graphics context on which we're drawing * @param xpos The x coordinate in tiles the tank is at * @param ypos The y coordinate in tiles the tank is at * @param rot The rotation of the tank */ public void drawTank(Graphics g, float xpos, float ypos, float rot) { // work out the centre of the tank in rendering coordinates and then // spit onto the screen int cx = (int) (xpos * 32); int cy = (int) (ypos * 32); g.rotate(cx,cy,rot); player.draw(cx-16,cy-16); g.rotate(cx,cy,-rot); }
Example 11
Source File: Circle.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
@Override public void draw(Graphics g, int trackPosition, float mirrorAngle) { Color orig = color; if (mirrorAngle != 0f) { color = mirrorColor; } int timeDiff = hitObject.getTime() - trackPosition; final int approachTime = gameState.getApproachTime(); final int fadeInTime = gameState.getFadeInTime(); float scale = timeDiff / (float) approachTime; float approachScale = 1 + scale * 3; float fadeinScale = (timeDiff - approachTime + fadeInTime) / (float) fadeInTime; float alpha = Utils.clamp(1 - fadeinScale, 0, 1); g.pushTransform(); if (mirrorAngle != 0f) { g.rotate(x, y, mirrorAngle); } if (GameMod.HIDDEN.isActive()) { final int hiddenDecayTime = gameState.getHiddenDecayTime(); final int hiddenTimeDiff = gameState.getHiddenTimeDiff(); if (fadeinScale <= 0f && timeDiff < hiddenTimeDiff + hiddenDecayTime) { float hiddenAlpha = (timeDiff < hiddenTimeDiff) ? 0f : (timeDiff - hiddenTimeDiff) / (float) hiddenDecayTime; alpha = Math.min(alpha, hiddenAlpha); } } float oldAlpha = Colors.WHITE_FADE.a; Colors.WHITE_FADE.a = color.a = alpha; if (timeDiff >= 0) { gameObjectRenderer.renderApproachCircle(x, y, color, approachScale); } gameObjectRenderer.renderHitCircle(x, y, color, hitObject.getComboNumber(), alpha); Colors.WHITE_FADE.a = oldAlpha; g.popTransform(); color = orig; }
Example 12
Source File: Slider.java From opsu-dance with GNU General Public License v3.0 | 4 votes |
/** * Draws slider ticks. * @param g graphics * @param trackPosition the track position * @param curveAlpha the curve alpha level * @param decorationsAlpha the decorations alpha level */ private void drawSliderTicks(Graphics g, int trackPosition, float curveAlpha, float decorationsAlpha, float mirrorAngle) { float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha); Image tick = GameImage.SLIDER_TICK.getImage().getScaledCopy(tickScale); // calculate which ticks need to be drawn (don't draw if sliderball crossed it) int min = 0; int max = ticksT.length; if (trackPosition > getTime()) { for (int i = 0; i < ticksT.length; ) { if (((trackPosition - getTime()) % sliderTime) / sliderTime < ticksT[i]) { break; } min = ++i; } } if (currentRepeats % 2 == 1) { max -= min; min = 0; } // calculate the tick alpha level float sliderTickAlpha; if (currentRepeats == 0) { sliderTickAlpha = decorationsAlpha; } else { float t = getT(trackPosition, false); if (currentRepeats % 2 == 1) { t = 1f - t; } sliderTickAlpha = Utils.clamp(t * ticksT.length * 2, 0f, 1f); } // draw ticks Colors.WHITE_FADE.a = Math.min(curveAlpha, sliderTickAlpha); for (int i = min; i < max; i++) { Vec2f c = curve.pointAt(ticksT[i]); g.pushTransform(); if (mirrorAngle != 0f) { g.rotate(c.x, c.y, mirrorAngle); } tick.drawCentered(c.x, c.y, Colors.WHITE_FADE); g.popTransform(); } }
Example 13
Source File: Game.java From opsu with GNU General Public License v3.0 | 4 votes |
/** * Draws hit objects, hit results, and follow points. * @param g the graphics context * @param trackPosition the track position */ private void drawHitObjects(Graphics g, int trackPosition) { // draw result objects (under) data.drawHitResults(trackPosition, false); // include previous object in follow points int lastObjectIndex = -1; if (objectIndex > 0 && objectIndex < beatmap.objects.length && trackPosition < beatmap.objects[objectIndex].getTime() && !beatmap.objects[objectIndex - 1].isSpinner()) lastObjectIndex = objectIndex - 1; boolean loseState = (playState == PlayState.LOSE); if (loseState) trackPosition = failTrackTime + (int) (System.currentTimeMillis() - failTime); // draw merged slider if (!loseState && mergedSlider != null && Options.isExperimentalSliderMerging()) { mergedSlider.draw(Color.white); mergedSlider.clearPoints(); } // get hit objects in reverse order, or else overlapping objects are unreadable Stack<Integer> stack = new Stack<Integer>(); int spinnerIndex = -1; // draw spinner first (assume there can only be 1...) for (int index : passedObjects) { if (beatmap.objects[index].isSpinner()) { if (spinnerIndex == -1) spinnerIndex = index; } else stack.add(index); } for (int index = objectIndex; index < gameObjects.length && beatmap.objects[index].getTime() < trackPosition + approachTime; index++) { if (beatmap.objects[index].isSpinner()) { if (spinnerIndex == -1) spinnerIndex = index; } else stack.add(index); // draw follow points if (Options.isFollowPointEnabled() && !loseState) lastObjectIndex = drawFollowPointsBetween(objectIndex, lastObjectIndex, trackPosition); } if (spinnerIndex != -1) stack.add(spinnerIndex); // draw hit objects while (!stack.isEmpty()){ int idx = stack.pop(); GameObject gameObj = gameObjects[idx]; // normal case if (!loseState) gameObj.draw(g, trackPosition); // death: make objects "fall" off the screen else { // time the object began falling int objTime = Math.max(beatmap.objects[idx].getTime() - approachTime, failTrackTime); float dt = (trackPosition - objTime) / (float) (MUSIC_FADEOUT_TIME); // would the object already be visible? if (dt <= 0) continue; // generate rotation speeds for each objects final float rotSpeed; if (rotations.containsKey(gameObj)) { rotSpeed = rotations.get(gameObj); } else { rotSpeed = (float) (2.0f * (Math.random() - 0.5f) * MAX_ROTATION); rotations.put(gameObj, rotSpeed); } g.pushTransform(); // translate and rotate the object g.translate(0, dt * dt * container.getHeight()); Vec2f rotationCenter = gameObj.getPointAt((beatmap.objects[idx].getTime() + beatmap.objects[idx].getEndTime()) / 2); g.rotate(rotationCenter.x, rotationCenter.y, rotSpeed * dt); gameObj.draw(g, trackPosition); g.popTransform(); } } // draw result objects (over) data.drawHitResults(trackPosition, true); }
Example 14
Source File: GraphicsTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics) */ public void render(GameContainer container, Graphics g) throws SlickException { g.setColor(Color.white); g.setAntiAlias(true); for (int x=0;x<360;x+=10) { g.drawLine(700,100,(int) (700+(Math.cos(Math.toRadians(x))*100)), (int) (100+(Math.sin(Math.toRadians(x))*100))); } g.setAntiAlias(false); g.setColor(Color.yellow); g.drawString("The Graphics Test!", 300, 50); g.setColor(Color.white); g.drawString("Space - Toggles clipping", 400, 80); g.drawString("Frame rate capped to 100", 400, 120); if (clip) { g.setColor(Color.gray); g.drawRect(100,260,400,100); g.setClip(100,260,400,100); } g.setColor(Color.yellow); g.translate(100, 120); g.fill(poly); g.setColor(Color.blue); g.setLineWidth(3); g.draw(poly); g.setLineWidth(1); g.translate(0, 230); g.draw(poly); g.resetTransform(); g.setColor(Color.magenta); g.drawRoundRect(10, 10, 100, 100, 10); g.fillRoundRect(10, 210, 100, 100, 10); g.rotate(400, 300, ang); g.setColor(Color.green); g.drawRect(200,200,200,200); g.setColor(Color.blue); g.fillRect(250,250,100,100); g.drawImage(image, 300,270); g.setColor(Color.red); g.drawOval(100,100,200,200); g.setColor(Color.red.darker()); g.fillOval(300,300,150,100); g.setAntiAlias(true); g.setColor(Color.white); g.setLineWidth(5.0f); g.drawOval(300,300,150,100); g.setAntiAlias(true); g.resetTransform(); if (clip) { g.clearClip(); } }