-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScreen.java
52 lines (40 loc) · 1.3 KB
/
Screen.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package InsaneGamesEngine;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
public class Screen {
public int width;
public int height;
private Surface surface;
private Surface nextFrameSurface;
private Graphics graphics;
private Graphics2D graphicsBufferImage;
private Graphics2D graphics2D;
public Screen(int width, int height, Graphics graphics) {
this.width = width;
this.height = height;
this.surface = new Surface();
this.nextFrameSurface = new Surface();
this.graphics = graphics;
graphics2D = (Graphics2D) graphics;
Dimension d = getSize();
int w = d.width;
int h = d.height;
// Cria um buffer para a imagem
BufferedImage buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
graphicsBufferImage = buffImg.createGraphics();
}
public void draw( GraphicImage graphicImage, Position position ) {
// TODO: nextFrameSurface.draw( graphicImage.getSurface() );
graphicsBufferImage.drawImage(graphicImage, (int)position.getX(), (int)position.getY(), null);
}
public void flip() {
// TODO: this.surface = this.nextFrameSurface;
Toolkit.getDefaultToolkit().sync();
// Desenha a imagem do buffer
graphics2D.drawImage(buffImg, null, 0, 0);
graphics.dispose();
}
}