Hello,
im in the thick of trying to make a game with a rotating ship i got along way with it but got stuck just on rotation now im just trying to figure out how to get a shape to rotate in java.
so i simplified all the code and back to basics but now im stuck it i just want the square to start spinning on the screen and i though i would use a for loop but it just stares at me stationary cursing my stupidity
please help
package rotate; import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferStrategy; public class Main extends Canvas implements Runnable { /** * */ private static final long serialVersionUID = 1L; public static final int WIDTH = 800, HEIGHT = WIDTH / 12*9; private Thread thread; private boolean running = false; public Main() { new Window(WIDTH, HEIGHT, "rotate", this); } public synchronized void start() { thread = new Thread(this); thread.start(); running = true; } public synchronized void stop() { try { thread.join(); running = false; }catch(Exception e) { e.printStackTrace(); } } public void run() { long lastTime = System.nanoTime(); double amountOfTicks = 60.0; double ns = 1000000000/ amountOfTicks; double delta = 0; long timer = System.currentTimeMillis(); int frames = 0; while(running) { long now = System.nanoTime(); delta += (now - lastTime) / ns; lastTime = now; while(delta >= 1) { tick(); delta--; } if(running) render(); frames++; if(System.currentTimeMillis() - timer > 1000) { timer += 1000; System.out.println("FPS: " + frames); frames = 0; } } stop(); } private void tick() { } private void render() { BufferStrategy bs = this.getBufferStrategy(); if (bs == null) { this.createBufferStrategy(3); return; } Graphics g = bs.getDrawGraphics(); Graphics2D g2d = (Graphics2D) g; int count = 0; for (int i = 0; i < 360; i++) { count++; } g.setColor(Color.BLACK); g.fillRect(0,0,WIDTH, HEIGHT); g.setColor(Color.BLUE); g.translate(100,100); for (int i = 0; i < 360; i++) { count++; g2d.rotate(Math.toRadians(count)); } g.fillRect(-25,-25,50,50); g.dispose(); bs.show(); } public static void main(String[] args) { new Main(); } }