我不能为我的生活弄清楚如何在我的乒乓球游戏窗口上创建一个填充的白色矩形.我在使用ShapeRenderer类时遵循了基本教程(https://www.youtube.com/watch?v=_MAi2H6lf0A),但由于某种原因,本教程使用以下行 -
ShapeRenderer.begin(ShapeRenderer.ShapeType.FilledRectangle)
但是,我正在使用的IDE不了解FilledRectangle是什么,并抛出无法解决的符号错误.
我导入了以下所有图书馆:
import com.badlogic.gdx.*;
import com.badlogic.gdx.backends.lwjgl.*;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.glutils.*;
import com.badlogic.gdx.math.*;
Run Code Online (Sandbox Code Playgroud)
有谁知道我可以尝试绕过这个?
我试图在libgdx中制作一个带有精灵表的简单动画,一个正在移动他腿的痘痘男人.这是代码:
package com.pro.schoolrun;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class SchoolRun implements ApplicationListener {
Texture player;
TextureRegion[] regions;
SpriteBatch batch;
OrthographicCamera camera;
int i;
@Override
public void create() {
i = 0;
player = new Texture(Gdx.files.internal("data/spritesheet.png"));
regions[0] = new TextureRegion(player, 0, 0, player.getWidth() / 4,
player.getHeight() / 2);
regions[1] = new TextureRegion(player, 64, 0, player.getWidth() / 4,
player.getHeight() / 2);
regions[2] = new TextureRegion(player, 128, 0, player.getWidth() / 4,
player.getHeight() / …Run Code Online (Sandbox Code Playgroud) 我在LibGDX中开发游戏,我想每隔ms调用一次更新函数.
但我不知道如何在我的情况下做到 -
while(gameLoop) {
renderWorld();
}
public void renderWorld() {
// Some rendering code here
if(world.map[mapPos].ID == 9) {
updateWater(mapPos); // This function makes the water animate, but i must put a time limit otherwise it will be too hard to see the animation, how can i limit this?
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到我想要更新水,我不能没有时间限制这样做,因为否则水"动画"将太快甚至看不到.
我在使用Android / IOs应用程序时遇到问题:库代码(libgdx?)抛出NPE,但不支持在RoboVM中进行调试。在Android中运行时,它可以按预期工作并达到该handleHttpResponse()方法。当在IO中运行时,它达到t(为Throwable t)失败的方法NullPointerException。我创建了一个示例应用程序来显示问题,也许这是我的错,所以这里是代码:
public class Npe extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
loadHttps("https://www.google.it");
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
private static void loadHttps(String url) {
HttpRequest httpGet = new HttpRequest(HttpMethods.GET);
httpGet.setUrl(url);
Gdx.net.sendHttpRequest(httpGet, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
String res = httpResponse.getResultAsString();
System.err.println("res = \"" …Run Code Online (Sandbox Code Playgroud) 我最近开始学习编程移动应用程序.我正在做一些练习,编写基本程序.首先我使用LibGDX,所以首先我在桌面上测试我的应用程序然后在android上测试它.
在我的程序的某个地方,它必须从0,1,2生成3个随机数(只要它们是随机的,它们可以是相同的数字).在桌面上我的程序运行正常,每次运行它时会生成3个随机数.但是,当我在我的Android手机上试用它时,所有三个数字都是相同的.例如3次试验:我的桌面:0-0-1,2-1-2,2-0-1我的手机; 0-0-0,2-2-2,0-0-0;
for (int x = 0; x < 3; x++){
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(3);
postNumber(randomNumber);//This function I wrote sends the randomNumber to be drawn on the screen
}
Run Code Online (Sandbox Code Playgroud) 我知道标题没有意义,但我想不出如何更好地说话,请耐心等待.
我正在使用java与LibGDX,我正在尝试从保存的像素图加载数据,以在屏幕上呈现地图.在像素图中,每个像素代表六边形的颜色(地图是六边形网格).
问题是:我将数据(特别是颜色)从像素图加载到我称为HexInfo的类的数组中.但是,当我将此数组传递给另一个类以便在我的屏幕上绘制它时,数组中的每个HexInfo项目的颜色都为黑色.以下是一切设置的方法
hexInfo = new HexInfo[cols][rows];
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
Color.rgba8888ToColor(color, savedScreenData.getPixel(i, j));
hexInfo[i][j] = new HexInfo(i,j);
hexInfo[i][j].setColour(color);
hexInfo[i][j].setIsVisible(true);
hexInfo[i][j].setIsOccupied(true);
//It is definitely set because this gives the correct colours
System.out.println(hexInfo[i][j].getColour());
}
}
mapScreen = new MapScreen(hexInfo);
Run Code Online (Sandbox Code Playgroud)
这里^,屏幕上打印的getColour是正确的.
然后,在MapScreen类中,我为每个hexInfo使用for循环来获取getColour:
public MapScreen(HexInfo[][] hexInfo)
{
cols = hexInfo.length;
rows = hexInfo[0].length;
for (int i = 0; i < cols; i++) {
for (int j = …Run Code Online (Sandbox Code Playgroud) 我试图基于使用? :语法的条件添加到一个列表或另一个列表,这在c#中是可能的,我使用的语法不能编译
List<int> Negatives = new List<int>();
List<int> Positives = new List<int>();
foreach (int number in numbers)
{
(number >= 0) ? Negatives.Add(number) : Positives.Add(number);
}
Run Code Online (Sandbox Code Playgroud) 可能只对libGDX技能负责.
MyGame.java:
public void create() { // gets called after constructor
Resources.setInstance(new Resources());
}
Run Code Online (Sandbox Code Playgroud)
Resources.java
public static void setInstance(Resources res) {
if (instance != null) {
instance = res;
}
else throw new IllegalStateException(
"instance cant be null");
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
Exception in thread "LWJGL Application" java.lang.IllegalStateException: instance cant be null
at com.mutant.td.Resources.setInstance(Resources.java:22)
at com.mutant.td.SpeciesWarGame.create(SpeciesWarGame.java:41)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Run Code Online (Sandbox Code Playgroud)
我真的不知道发生了什么.