Bewegen anstatt "repaint"?

Sway

Erfahrenes Mitglied
Hi,

ist es möglich ein Image oder eine Zeichnung ohne Repaint eine andere Positon zuzuordnen? Ich würde gerne sowas wie ein Ball hüpfen lassen. Das blöde dabei ist nur das er zu flackern anfängt.
 
Hallo!

Schau mal hier:
Code:
package de.tutorials;

import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;

public class FlyBall extends JFrame {
	
	private BufferStrategy strategy;
	
	private Thread animator = new Thread(){
		int x, y;
		public void run(){
			while(true){
				Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
				g.clearRect(0,0,320,240);
				g.fillOval((x+=4) % 320,(y+=3) % 240,25,25);
				g.dispose();
				strategy.show();
				try {
					Thread.sleep(20L);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	};
	
	public FlyBall(){
		super("BallJumb");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setIgnoreRepaint(true);
		setSize(320,240);
		setVisible(true);
		createBufferStrategy(2);
		strategy = getBufferStrategy();
	}

	public static void main(String[] args) {
		new FlyBall().start();
	}

	private void start() {
		animator.start();
	}
}

Gruß Tom
 

Neue Beiträge

Zurück