"Vsync" simulado para evitar el shutering
This commit is contained in:
@@ -142,7 +142,7 @@ public class Arkanoid {
|
||||
for (Actor actor : actores) {
|
||||
actor.actua();
|
||||
}
|
||||
canvas.repaint();
|
||||
canvas.pintar();
|
||||
}
|
||||
|
||||
long tiempoTranscurrido = new Date().getTime() - tiempoInicio;
|
||||
|
||||
@@ -3,11 +3,14 @@ package net.h4ckx0r;
|
||||
import net.h4ckx0r.actores.Actor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.util.List;
|
||||
|
||||
public class MiCanvas extends Canvas {
|
||||
List<Actor> actores = null;
|
||||
|
||||
private BufferStrategy strategy = null;
|
||||
|
||||
private int[][] estrellitas = null;
|
||||
|
||||
public MiCanvas(List<Actor> actores) {
|
||||
@@ -24,9 +27,18 @@ public class MiCanvas extends Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
this.setBackground(Color.BLACK);
|
||||
public void pintar() {
|
||||
|
||||
if (this.strategy == null) {
|
||||
this.createBufferStrategy(2);
|
||||
strategy = getBufferStrategy();
|
||||
Toolkit.getDefaultToolkit().sync();
|
||||
}
|
||||
|
||||
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect(0,0, this.getWidth(), this.getHeight());
|
||||
|
||||
for (int[] estrella : estrellitas) {
|
||||
g.setColor(Color.GRAY);
|
||||
@@ -36,6 +48,8 @@ public class MiCanvas extends Canvas {
|
||||
for (Actor actor : actores) {
|
||||
actor.paint(g);
|
||||
}
|
||||
|
||||
strategy.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user