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