-
Notifications
You must be signed in to change notification settings - Fork 1
/
Screen.java
60 lines (47 loc) · 1.38 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
53
54
55
56
57
58
59
60
import javax.imageio.ImageIO;
import java.io.File;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
public abstract class Screen implements Renderable{
protected Window gw;
protected BufferedImage screenImage;
protected Graphics2D screenGraphics;
protected Input input;
protected int width;
protected int height;
protected int fillColor = Color.BLACK.getRGB();
public static final double defaultFPS = 60.0;
public static final int secondInNano = 1000000000;
public static double FPS = defaultFPS;
public static double ns = secondInNano/FPS;
public Screen(Window gw, int width, int height){ /*, int canvasWidth, int canvasHeight*/
this.gw = gw;
this.width = width;
this.height = height;
screenImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
screenGraphics = screenImage.createGraphics();
}
public Input getInput(){
return input;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public Window getWindow(){
return gw;
}
public abstract void render();
public void draw(Graphics2D g){
//refreshImage();
render();
JFrame frame = gw.getFrame();
g.drawImage(screenImage,0,0,frame.getContentPane().getWidth(),frame.getContentPane().getHeight(),0,0,width,height,null);
}
}