Java 我一直在尝试为3d游戏绘制像素,我';我没有收到任何错误,但它没有';行不通
这是我的主要课程:Java 我一直在尝试为3d游戏绘制像素,我';我没有收到任何错误,但它没有';行不通,java,Java,这是我的主要课程: package Main; import java.awt.Canvas; import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; imp
package Main;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import Graphics.Render;
import Graphics.Screen;
public class Run extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
private int[] pixels;
private Render render;
private Screen screen;
private BufferedImage img;
private Thread MainThread;
private static Image Icon;
private static final int Fps = 60;
private final static int Width = 800;
private final static int Height = 600;
private static Boolean Running = false;
public Run() {
Start();
ClassLoader cl = this.getClass().getClassLoader();
Icon = new ImageIcon(cl.getResource("Resources/Textures/Icon.png")).getImage();
screen = new Screen(Width, Height);
img = new BufferedImage(Width, Height, BufferedImage.TYPE_INT_RGB);
pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
System.out.println("[System] Main Method Successfuly Loaded");
}
public void run() {
while (Running == true) {
MainThread.start();
Render();
Update();
}
}
public synchronized void Start() {
Running = true;
if (Running == true) {
System.out.println("[System] Starting...");
}
}
public synchronized void Stop() {
Running = false;
try {
MainThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
System.exit(0);
}
}
public synchronized void Render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
screen.render();
for (int i = 0; i < Width * Height; i++) {
pixels[i] = screen.pixels[i];
}
Graphics g = bs.getDrawGraphics();
g.drawImage(img, 0, 0, Width, Height, null);
g.dispose();
bs.show();
}
public synchronized void Update() {
}
public static void main(String[] args) {
JFrame Frame = new JFrame();
Run Run = new Run();
Frame.add(Run);
Frame.pack();
Frame.setResizable(true);
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame.setSize(Width, Height);
Frame.setIconImage(Icon);
Frame.setTitle("Space Infinity Pre-Alpha 1.0.0");
Frame.setLocationRelativeTo(null);
Frame.setVisible(true);
System.out.println("[System] Window Successfuly Created and Rendered");
}
}
packagemain;
导入java.awt.Canvas;
导入java.awt.Graphics;
导入java.awt.Image;
导入java.awt.image.BufferStrategy;
导入java.awt.image.buffereImage;
导入java.awt.image.DataBufferInt;
导入javax.swing.ImageIcon;
导入javax.swing.JFrame;
导入图形。渲染;
导入图形。屏幕;
公共类Run扩展了Canvas实现Runnable{
私有静态最终长serialVersionUID=1L;
私有int[]像素;
私人渲染;
私人屏幕;
专用缓冲图像img;
私有线程主线程;
私有静态图像图标;
专用静态最终整数Fps=60;
专用最终静态整数宽度=800;
专用最终静态内部高度=600;
私有静态布尔运行=false;
公营{
Start();
ClassLoader cl=this.getClass().getClassLoader();
Icon=newimageicon(cl.getResource(“Resources/Textures/Icon.png”)).getImage();
屏幕=新屏幕(宽度、高度);
img=新的BuffereImage(宽度、高度、BuffereImage.TYPE\u INT\u RGB);
像素=((DataBufferInt)img.getRaster().getDataBuffer()).getData();
System.out.println(“[System]主方法已成功加载”);
}
公开募捐{
while(Running==true){
MainThread.start();
Render();
更新();
}
}
公共同步的void Start(){
运行=真;
if(Running==true){
System.out.println(“[System]启动…”);
}
}
公共同步无效停止(){
运行=错误;
试一试{
MainThread.join();
}捕捉(中断异常e){
e、 printStackTrace();
系统出口(0);
}
}
公共同步的void Render(){
BufferStrategy bs=this.getBufferStrategy();
如果(bs==null){
创新战略(3);
回来
}
screen.render();
对于(int i=0;i
这是我的主要渲染类:
package Graphics;
public class Render {
private final int width;
private final int height;
public final int[] pixels;
public Render(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}
public void draw(Render render, int xoffset, int yoffset) {
for (int y = 0; y < render.height; y++) {
int yPix = y + yoffset;
for (int x = 0; x < render.width; x++) {
int xPix = x + xoffset;
pixels[xPix + yPix * width] = render.pixels[x + y * render.width];
}
}
}
}
封装图形;
公共类渲染{
私有最终整数宽度;
私人最终整数高度;
公共最终整数[]像素;
公共渲染(整数宽度、整数高度){
这个。宽度=宽度;
高度=高度;
像素=新整数[宽度*高度];
}
公共无效绘制(渲染渲染、int-xoffset、int-yoffset){
对于(int y=0;y
这是我的屏幕课程:
package Graphics;
import java.util.Random;
public class Screen extends Render {
private Render test;
public Screen(int width, int height) {
super(width, height);
Random random = new Random();
test = new Render(256, 256);
for (int i = 0; i < 256 * 256; i++) {
test.pixels[i] = random.nextInt();
}
}
public void render() {
draw(test, 0, 0);
}
}
封装图形;
导入java.util.Random;
公共类屏幕扩展渲染{
私人渲染测试;
公共屏幕(整数宽度、整数高度){
超级(宽度、高度);
随机=新随机();
测试=新渲染(256,256);
对于(int i=0;i<256*256;i++){
test.pixels[i]=random.nextInt();
}
}
公共无效呈现(){
绘制(测试,0,0);
}
}
现在,我不明白我做错了什么,这以前是有效的,但现在它没有给我任何错误,但它没有绘制像素?在“Run”类中,方法Run需要@Override指令,以实现该Run方法我尝试了它,但没有做任何事情。