Kann mir einer sagen, warum sich meine Entities nicht bewegen ? Steh wohl auf dem Schlauch.
Hier die benötigten Methoden:
[/code]
ENTITY CLASS
Vielen Dank im Vorraus!
Hier die benötigten Methoden:
Java:
public void paintComponent(Graphics g){
super.paintComponent(g);
drawFps(g);
for(Entity e: actors){
e.draw(g);
}
}
Java:
public void moveEntities(){
for(Entity e : actors){
e.move(delta);
}
}
[/code]
Java:
private void computeDelta(){
delta = System.nanoTime() - last;
last = System.nanoTime();
fps = ((long) 1e9)/delta;
}
Java:
public void run(){
while(running){
computeDelta();
moveEntities();
repaint();
try {
Thread.sleep(15);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
ENTITY CLASS
Java:
public class Entity {
public static int WIDTH = 25;
public static int HEIGHT = 25;
public static float MOVING_SPEED = 0.5f;
private int dx = 1;
private int dy = 1;
private int x;
private int y;
public Entity(EntityType type, int x, int y){
this.x = x;
this.y = y;
}
public void move(long delta){
x += (MOVING_SPEED * (delta/1e9));
}
public void draw(Graphics g){
g.setColor(Color.RED);
g.fillRect(x, y, WIDTH, HEIGHT);
}
}
Vielen Dank im Vorraus!
Zuletzt bearbeitet: