Tag: libgdx

video驱动程序不支持OpenGL

当我使用这段代码时: import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; public class Main { public static void main(String[] args) { LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); cfg.title = “MtxJungleGameMenu”; cfg.useGL20 = false; cfg.width = 800; cfg.height = 480; new LwjglApplication(new MainStarter(), cfg); } } 我得到这样的例外: 线程“LWJGL Application”中的exceptioncom.badlogic.gdx.utils.GdxRuntimeException:com.badlogic.gdx.utils.GdxRuntimeException:video驱动程序不支持OpenGL。 任何帮助?

LibGDX没有使用Android资源文件夹

我在编译Android或IOS版本时读取assets文件夹的libGDX项目有问题。 在尝试访问android模块下的assets文件夹中的文件时,我似乎总是在IOS或Android中获得FileNotFoundException,但在桌面上运行时却没有。 我的桌面配置指向Android资源目录。 执行以下代码时: public void readGameMap() throws IOException { readGameMap(“gameMap.txt”); } public void readGameMap(String path) throws IOException { Scanner s = new Scanner(Gdx.files.internal(path).file()); int i = 0; while ((s.hasNextLine())) { String str = s.nextLine(); if (str.length() < maze.length) throw new IOException("Incorrect game_map.txt structure"); for (int j = 0; j < str.length(); j++) { Object […]

如何翻转像素图以绘制到libgdx中的纹理?

所以我要做的是通过将pixmaps绘制到纹理来为我的游戏生成背景图像。 到目前为止,我可以做到这一点,但现在我需要绘制在X或Y轴上翻转到纹理的像素图。 但是我找不到任何可以做到的事情。 pixmap类不提供该function。 然后我想我可以在纹理上绘制一个翻转的纹理区域,但到目前为止我还没有找到如何做到这一点。 所以我想知道我怎么能做这样的事情,是否可以用其他java库翻转png图像,然后从翻转的图像创建一个像素图?

libgdx – 如何使用包装文本获取Label

我尝试了以下代码: Label label = new Label(reallyLongString, skin); label.setWrap(true); label.setWidth(100); // or even as low as 10 table.add(label); … 然而我得到的只是一条非常宽的线条,从屏幕上消失。

加载九个补丁图像作为Libgdx Scene2d按钮背景看起来很糟糕

我正在尝试使用Nine Patch作为Libgdx Scene2d UI按钮的背景。 这是装载,但它真的很难看。 我可以看到“元数据”像素,它被拉伸就好像它只是一个普通的图像(按钮上的文字是“继续”): 我正在通过(libgdx) NinePatch将.9.png文件直接加载到(libgdx) NinePatch如下所示: this.dialogButtonUp = new NinePatchDrawable( new NinePatch(new Texture(Gdx.files.internal(“data/button-round.9.png”)))); this.dialogButtonDown = new NinePatchDrawable( new NinePatch(new Texture(Gdx.files.internal(“data/button-round-down.9.png”)))); 然后我创建一个描述按钮的TextButtonStyle ,并引用两个NinePatch drawable: TextButton.TextButtonStyle buttonStyle = new TextButton.TextButtonStyle(); buttonStyle.font = aValidFontReally; buttonStyle.fontColor = Color.BLACK; buttonStyle.up = this.dialogButtonUp; buttonStyle.down = this.dialogButtonDown; buttonStyle.pressedOffsetX = -2; 我通过Dialog间接构建按钮: new Dialog( … ).button(“Continue”, null, buttonStyle); 我检查了.9.png文件以确保: 资产文件在Eclipse中刷新 […]

LibGDX 0.9.9 – 在环境中应用立方体贴图

我正在使用LibGDX 0.9.9。 我正在尝试渲染立方体贴图和雾。 所以我的代码片段如下: public void show() { modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 1.0f, 0.4f, 0.4f, 1f)); environment.set(new ColorAttribute(ColorAttribute.Fog, 0.9f, 1f, 0f, 1f)); environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); cubemap = new Cubemap(Gdx.files.internal(“cubemap/pos-x.png”), Gdx.files.internal(“cubemap/neg-x.png”), Gdx.files.internal(“cubemap/pos-y.png”), Gdx.files.internal(“cubemap/neg-y.png”), Gdx.files.internal(“cubemap/pos-z.png”), Gdx.files.internal(“cubemap/neg-z.png”)); environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(1f, 1f, […]

LibGDX – 调用TiledMapRenderer.render()时应用程序崩溃

@Override public void render(float delta) { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); sprite.setProjectionMatrix(camera.combined); mLevel.getTiledMapRenderer().getProjectionMatrix().set(camera.combined); Vector3 tmp = new Vector3(); tmp.set(0, 0, 0); camera.unproject(tmp); mLevel.getTiledMapRenderer().render(tmp.x, tmp.y, camera.viewportWidth, camera.viewportHeight); sprite.begin(); … sprite.end(); } 这是我在启动桌面版时得到的: Exception in thread “LWJGL Application” java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 1. Because at most 1 elements can be returned, a […]

LibGDX – 使用Modelbuilder.createBox将单个纹理映射到框的每个面

我有以下代码片段,可生成3D多维数据集: ModelBuilder modelBuilder = new ModelBuilder(); box = modelBuilder.createBox(2f, 2f, 2f, new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0])), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates ); 到现在为止还挺好。 问题是立方体的所有面都使用相同的纹理,而我想要的是Assetloader.tr [],它是一个具有6个单独纹理的数组,分别出现在每个面上。 我努力了 box.nodes.get(0).parts.get(0).material.set(new Material(TextureAttribute.createDiffuse(AssetLoader.tr[0]))); box.nodes.get(0).parts.get(1).material.set(new Material(TextureAttribute.createDiffuse(AssetLoader.tr[1]))); … 但不知何故,文档没有给我任何关于如何正确执行它的提示。 我有点被困在这里。

如何在LibGDX中进行混合

我基本上想在LibGDX中使用混合模式,但不知道该怎么做。 我在互联网上找到了这个图像。 我想在LibGDX上做同样的事情。 有人可以教我怎么做。 我一直在玩Scene2D。 这是我的非工作片段。 private class MyGroup extends Group { Image red, blue; public MyGroup() { Texture texture = new Texture(Gdx.files.internal(“images/red.png”)); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); red = new Image(texture); texture = new Texture(Gdx.files.internal(“images/blue.png”)); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); blue = new Image(texture); red.setX(-25); blue.setX(25); } @Override public void draw(Batch batch, float parentAlpha) { batch.end(); batch.begin(); batch.enableBlending(); red.draw(batch, parentAlpha); […]

LibGdx-ViewPort的宽度和高度与某些设备不匹配

我正在使用Viewport作为我的libGdx风景游戏。 public static final int WORLD_WIDTH = 1280; public static final int WORLD_HEIGHT = 800; camera = new OrthographicCamera(); float aspectRatio = Constants.WORLD_WIDTH / Constants.WORLD_HEIGHT; ViewPort viewPort = new FillViewport(WORLD_WIDTH * aspectRatio,WORLD_HEIGHT, camera); 我正在使用这个宽度和高度的所有位置。 它在除屏幕分辨率大于1300的设备之外的所有设备中都能正常工作。在分辨率高于1300的设备中,只有游戏的中间部分可见。我尝试使用拉伸视口来获得更高分辨率的设备,但它给出的是所有游戏元素都拉长了 如何让我的游戏在所有设备上运行良好?我需要更改视口吗?