Synchronous responses to `Gdx.net.sendHttpRequest` in LibGDX

I'm making a small game in LibGDX. I'm saving the player's username locally as well as on a server. The problem is that the application is not waiting for the result of the call so the online database's ID is not saved locally. Here's the overall flow of the code: //Create a new user object User user = new User(name); //Store the user in the online database NetworkService networkService = new NetworkService(); String id = networkService.saveUser(user); //Set the newly generated dbase ID on the local object user.setId(id); //Store the user locally game.getUserService().persist(user); in this

2021-07-13 17:26:19    分类:问答    asynchronous   libgdx

Libgdx : setting another screen, but still buttons from old screen active

In my libgdx game, I have 2 screens, menu and list. When I click on a label in the menu screen, I do a setscreen(list). The new screen shows up, and the menu screen alongwith its labels disappears. But when I click on the same positions (from menu screen where the labels were, but of course those labels are not showing as I have changed screens) the click event responds. Why? note:My list screen currently has not event handlers for any widget. When switching screens do I need to do anything more than just setscreen(anotherscreen) to deactivate oldscreen?

2021-07-13 04:53:02    分类:问答    java   android   libgdx

Nesting ShapeRenderer.begin/end in SpriteBatch.begin/end

Is it possible to draw shapes by using ShapeRenderer between SpriteBatch begin and end calls. I have tried but no result, only SpriteBatch textures are drawn, no shape is on the scene. Sample code is as followed below : shapeRenderer.begin(ShapeType.FilledCircle); shapeRenderer.setColor(0f, 1f, 0f, 1f); shapeRenderer.filledCircle( 100, 100, 100); shapeRenderer.end(); I have a orthographic camera created by these commands : camera = new OrthographicCamera(1, Gdx.graphics.getHeight() / Gdx.graphics.getWidth()); camera.setToOrtho(true);

2021-07-13 03:39:16    分类:问答    java   render   libgdx   shape

有没有办法忽略 libgdx 图像限制? (图片必须是二的幂)(Is there any way to ignore libgdx images Limitation? (images must be power of two))

问题 在libgdx framework我们只能使用图像的 2 次幂( 64x256 、 128x32等),因为 OpenGL 需要它。 有什么好方法可以“通过”这个限制吗? 例如:使用图像800x480 。 回答1 设置Texture.setEnforcePotImages(false); 并且您不再有限制。 因此,您只能使用大小为 2 的幂的图片是不正确的。 它只是“可以拥有”而不是“必须拥有”。 问候 回答2 您可以使用非锅纹理,例如通过使用 opengl es2.0。 但至少尝试使用锅纹理是一种很好的做法。 例如,通过将多个图像打包到一个纹理中。 这也减少了纹理切换的数量。 请参阅:http://code.google.com/p/libgdx/wiki/TexturePacker。 回答3 在加载图像之前执行此操作: GLTexture.setEnforcePotImages (false); 这将忽略 2 次幂检查。 回答4 最佳做法是不要直接使用您的图像。 而是使用 LibGdx nightlies 中可用的 TexturePacker 工具来生成图像图集。 要了解更多信息:- https://github.com/libgdx/libgdx/wiki/Texture-packer 回答5 对于某些纹理,您可以将其设为2 的幂。 对于 800 X 480 的背景

2021-07-13 00:01:41    分类:技术分享    android   opengl-es   libgdx   game-engine

单击 libGDX 中的 Actor(Click through an Actor in libGDX)

问题 我的游戏中有一个覆盖层,它由一个屏幕图像和一组位于屏幕“上”的按钮组成。 截屏: 我的Screen有一个Stage 。 Stage有一组Group对象,我认为它们是层。 第一组有背景,中间的组有游戏元素,最前面的组有屏幕叠加。 覆盖层由一个Image 、屏幕本身和四个TextButton (每个角落一个)组成。 如果不是因为我不能点击游戏层中的任何东西,只要覆盖层中的图像在它前面,这会很好用。 即使图像是透明的,它仍然会在到达游戏层之前拦截所有触摸事件。 所以我的问题是:如何让叠加层中的图像忽略所有触摸事件,以便游戏层获得它们并且可以真正玩游戏? 我自己尝试了一个想法,但我不确定这是正确的方法:我尝试将图像创建为一个自定义Actor ,该Actor始终将高度/宽度设置为 0,但仍然(通过重载 draw() 方法) 在整个屏幕上绘制图像。 这非常有效,除了图像由于某种原因被绘制在较低层的元素后面。 截图:https://dl.dropboxusercontent.com/u/1545094/Screen2.png 在此屏幕截图中,我打开了一个指令消息框,将其添加到游戏层之一(第 6 组)。 请注意,覆盖层(第 7 组)中的所有按钮都位于消息框的前面,但屏幕框架(这是一个自定义 Actor)以某种方式被绘制在消息框的后面。 这是为什么? 注意:如果我采用完全相同的情况

2021-07-12 22:29:11    分类:技术分享    java   layout   libgdx

Libgdx - 从 Rectangle.overlap(Rectangle) 获取交点矩形(Libgdx - Get Intersection Rectangle from Rectangle.overlap(Rectangle))

问题 有什么方法可以像 c# http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.rectangle.intersect.aspx 中的 Rectangle 一样知道 libgdx 中两个 Rectangles 之间的交集 Rectangle 区域吗? 我需要获取这两个矩形之间的相交矩形区域,但是无论两个矩形是否相交,libgdx 中的重叠方法只返回布尔值。 我已经阅读了 Intersector 类,但它没有提供任何帮助。 回答1 事实上,LibGDX 没有内置这个功能,所以我会做这样的事情: /** Determines whether the supplied rectangles intersect and, if they do, * sets the supplied {@code intersection} rectangle to the area of overlap. * * @return whether the rectangles intersect */ static public boolean intersect(Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection) { if

2021-07-12 19:57:27    分类:技术分享    java   android   eclipse   libgdx

Libgdx FreeTypeFontGenerator with AssetManager

i'd like to use the asset manager in combination with the FreeTypeFontGenerator. I dont want to load fnt files cause they display differently on different screenresolutions. So what i do currently is generating my fonts on the fly in every actor or screen. Now i think its best to generate the fonts once when the game is started and load them into the asset manager. But the AssetManager seems to need a filename with the BitmapFont.class parameter. What i want to do is generate 5 different bitmapfonts and and load those BitmapFonts into the assetmanager, so i have all my ressources in one place

2021-07-12 19:05:34    分类:问答    fonts   libgdx   asset-management

Reuse code when using screens in Libgdx

From what I understand when reading other peoples code on how to make different screens. You do a main handler class sort of... And then create a new class for each screen. The thing that confuses me is that whenever you create a new screen, you have to redefine everything that's going to be rendered, like SpriteBatch, sprites, fonts, etc. Is there any way to reuse these kind of things in all screens? I mean, if I have 10 screens, and want to be able to draw text on every screen. Is it really good programming practice to make a new BitmapFont for all 10 screen classes?

2021-07-12 18:44:45    分类:问答    java   android   libgdx

libGDX - How to clip

I have one SpriteBatch in my game, between whose batch.begin() and batch.end() I draw... a large static background image several game sprites I want to clip the area in which the sprites are seen, which I've read is done using ScissorStack. The problem is that ScissorStack appears to clip the entire SpriteBatch that's sent to the GPU. The result is that it clips my game sprites and the background image. Question: Must I have two separate batch.begin() and batch.end() cycles, one without clipping for the background, and another with clipping for the sprites? Or is there a way of clipping just

2021-07-12 13:18:48    分类:问答    libgdx   clipping

在模型/网格上重复纹理(Repeating Texture on Model/Mesh)

问题 当我在 SpriteBatch 上绘制纹理并设置 TextureWrap.Repeat 时,一切正常。 但是现在我有 3D 场景,我想要地面和纹理必须在模型/网格上重复,但这不起作用。 public static StillModel createPlainMesh(float xs, float zs, Texture texture) { final Mesh mesh = new Mesh(true, 4, 6, new VertexAttribute( Usage.Position, 3, "a_position"), new VertexAttribute( Usage.TextureCoordinates, 2, "a_texCoords")); mesh.setVertices(new float[] { xs, 0f, zs, 0, 0, xs, 0f, -zs, 0, 1, -xs, 0f, zs, 1, 0, -xs, 0f, -zs , 1,1 }); mesh.setIndices(new short[] { 0, 1, 2, 1, 2, 3 }); final StillModel model = new StillModel(new StillSubMesh( "ground", mesh, GL10.GL_TRIANGLES, new

2021-07-12 13:06:01    分类:技术分享    java   android   3d   libgdx