我正在使用 libGDX,我想重现我们可以在 Terraria 或 Go To Hell 等游戏中找到的水行为。水必须能够在重力作用下流动并使其形状适应容器的形状。
实际上我真的不知道要开始,因此我没有代码可以显示。我找到了一些关于水效果的教程,例如 Box2D 的反射或物理效果,但没有我想要的项目。如果你有一些线索那就太好了。
谢谢 !
我正在使用 libgdx 开发一款游戏,该游戏只有一个按钮让玩家跳跃。我正在尝试找出一种方法,使用户可以将该键重新绑定到他们想要的任何键。在 keyUp 和 keyDown 方法中,您会获得一个键码,我想知道是否有其他方法可以检查该键是什么,而不是遍历所有键。
if(keycode == Input.Keys.A){}
if(keycode == Input.Keys.B){}
if(keycode == Input.Keys.C){}
Run Code Online (Sandbox Code Playgroud)
等等。
我正在使用 Freetype 字体来显示文本。但字体总是看起来:#1不可读(通过减小字体大小):
generator = new FreeTypeFontGenerator(Gdx.files.internal("Fonts/LDFComicSans.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 5;
font = generator.generateFont(parameter); // font size 12 pixels
font.setColor(Color.BLACK);
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
generator.dispose();
Run Code Online (Sandbox Code Playgroud)
generator = new FreeTypeFontGenerator(Gdx.files.internal("Fonts/LDFComicSans.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 30;
font = generator.generateFont(parameter); // font size 12 pixels
font.setColor(Color.BLACK);
font.getData().setScale(0.15F, 0.15F);
font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
generator.dispose();
Run Code Online (Sandbox Code Playgroud)
这些是我使用的相机/视口设置:
camera = new OrthographicCamera(1280, 720);
batch = new SpriteBatch();
viewport = new StretchViewport(100,100,camera);
viewport.apply();
Run Code Online (Sandbox Code Playgroud)
我认为这是因为视口太小,但我真的不想改变它。有谁知道如何解决这一问题?
我想将桌面游戏的最小尺寸限制为 170x267。我目前正在使用这段代码:
@Override
public void resize(int width, int height) {
gamePort.update(width, height);
if (Gdx.app.getType() == ApplicationType.Desktop) {
if (width < 170)
Gdx.graphics.setWindowedMode(170, height);
if (height < 267)
Gdx.graphics.setWindowedMode(width, 267);
}
}
Run Code Online (Sandbox Code Playgroud)
然而,这会将窗口的 X 和 Y 位置设置为中心,有时会导致游戏窗口变为空白。
如何设置游戏窗口的最小尺寸?
我想重命名我的整个包,即重old.and.bad
命名为new.and.good
.
当我尝试重构->重命名核心项目时,它只为我提供了重命名包的最后一个标识符的选项,在上面的示例中为“bad”。
尝试重命名 Android 项目也是如此。
我如何重构以便每个项目(ios、android、core)更改其名称的每个部分?
我正在尝试使用此代码执行以下布局(宽度和高度仅用于调试,理想情况下我会让两个表都有 50% 的宽度。而且超类是 a Table
)
left().top()
add(Label("Player name", UI_SKIN)).center().expandX()
row()
add(Table()).width(50f).height(50f)
add(Table()).width(200f).height(50f)
setDebug(true, true)
Run Code Online (Sandbox Code Playgroud)
结果是,由于某种原因,表格似乎没有在自己的行上,而是最后一个表格将标签推到左侧。如果我只添加一个表,它就可以正常工作(无法添加另一个屏幕截图,因为我没有足够的代表......)。
任何帮助将不胜感激,我现在已经没有想法了。
我不能为我的生活弄清楚如何在我的乒乓球游戏窗口上创建一个填充的白色矩形.我在使用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)
有谁知道我可以尝试绕过这个?
我试图创建具有xpos,ypos,type和存储在其中的modelInstance的3D立方体.当我尝试运行该程序时,我收到此错误:
线程"LWJGL Application"中的异常org.lwjgl.opengl.OpenGLException:禁用数组缓冲区对象时不能使用偏移量
我该如何启用它?
这是我收到错误的类:
package com.me.the_unknown;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.materials.Material;
import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
public class Blocks {
public static ArrayList<Float> blockX = new ArrayList<Float>();
public static ArrayList<Float> blockY = new ArrayList<Float>();
public static ArrayList<Integer> blockType = new ArrayList<Integer>();
public static ArrayList<ModelInstance> blockModelInstance = new ArrayList<ModelInstance>();
public static ModelBatch modelBatch;
private static ModelBuilder modelBuilder;
//Textures
public static Texture stonebrick = new Texture("data/blocks/stonebrick.png");
public static Texture gravel = new Texture("data/blocks/gravel.png"); …
Run Code Online (Sandbox Code Playgroud) 我正在使用libgdx来开发mygame.
我正在使用GestureListener来处理我的触摸事件.我的目标是当玩家在屏幕上触摸时让角色向右或向左移动.
问题是,GestureListener没有任何方法来处理这个问题.如果我正在使用平移,则播放器必须滑动才能触发该方法.此外,GestureListener没有touchUp方法,所以我无法组合touchDown和touchUp.
有没有办法做到这一点?
我在libGdx中有背景问题.我试着解决我的问题:
"在你的create()方法中,创建一个引用你的image.png的新纹理,然后使用你现有的SpriteBatch在render()循环中渲染它.立即在你的GL.clear()调用之后,去你的batch.draw( backgroundTexture,0.0)并确保您的相机处于OrthographicProjection模式."
我这样做:
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(image, 250, 200);
batch.draw(backGroundImage, 0, 0);
batch.end();
Run Code Online (Sandbox Code Playgroud)
"图像"是我的正常纹理(它是简单的图像),"backGround"是ofc.我的背景.我的"backGround"应用于我的create()方法.我的相机已开启 camera = new OrthographicCamera();
.以下是我看到的内容:...我需要10点声望才能添加图像:<...图像是短的,切割左侧和右侧...我做错了什么.在这个解决方案的链接!和[熊猫] [1] Shinzul的参考风格链接说了一些关于循环in render(),也许这是我的问题,但我不知道如何解决这个问题.请帮忙.