gpt4 book ai didi

java - LibGDX 渲染未调用

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:55 27 4
gpt4 key购买 nike

我的 LibGDX 有问题。这是一个空白项目,只是使用套接字连接到其他程序。当我尝试启动它时,它只是挂起,程序没有响应。套接字连接已建立并正在工作。感谢您的帮助~BeefEX

package com.beefcodes.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class MyGdxGame extends ApplicationAdapter {

SpriteBatch batch;
BitmapFont font;

String lastMsg = "test";

Socket socket;
PrintWriter output;
BufferedReader input;

@Override
public void create () {
batch = new SpriteBatch();
font = new BitmapFont();
try {
socket = new Socket("localhost", 540);
} catch (IOException e) {
e.printStackTrace();
}
}


public void render () {
if (input == null && output == null) {
try {
output = new PrintWriter(socket.getOutputStream(), true);
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
}
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
String s;
try {
if ((s = input.readLine()) != null)
lastMsg = s;
} catch (IOException e) {
e.printStackTrace();
}
font.draw(batch, lastMsg, 100, 100);
batch.end();
}
}

最佳答案

从渲染方法中删除它

 if (input == null && output == null) {
try {
output = new PrintWriter(socket.getOutputStream(), true);
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {
e.printStackTrace();
}
}

您不想每秒创建 60 个 PrintWriter 和 60 个 BufferedReader。另外,我什至不知道这些被用在哪里。无论如何,也许这可以在 create 方法中完成一次。

关于java - LibGDX 渲染未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38077522/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com