libgdx

Unit-testing of libgdx-using classes

徘徊边缘 提交于 2019-12-03 13:19:56
问题 I'm writing a game over libgdx; I'm using the junit framework to simplify unit-testing my code. Now there's part of the code (a map generator, a class converting my own map format into TiledMap...) which I need to test thoroughly, but it uses libgdx code: from file handling to asset loading. I'm not planning to test the actual graphical output, or the game itself, in this way: but I want to test the single components (calculation, asset access...) to avoid blatant errors. I've tried to do

What is the difference between “Game”, “Screen” and “ApplicationAdapter” in libgdx?

拈花ヽ惹草 提交于 2019-12-03 12:46:09
In tutorials sometimes people use "extends Game", sometimes "implements Screen" and i have auto-generated "extends ApplicationAdapter". What is the difference between them? ApplicationAdapter allows you to create a listener, but not being forced to implement every method. If you're familiar with Swing, check out KeyAdapter , it's the same idea. An ApplicationListener allows you to handle application events. This allows you to execute code during certain events within the application life-cycle (such as destroy). An ApplicationListener is called when the Application is created, resumed,

libgdx coordinate system differences between rendering and touch input

天涯浪子 提交于 2019-12-03 12:12:50
问题 I have a screen (BaseScreen implements the Screen interface) that renders a PNG image. On click of the screen, it moves the character to the position touched (for testing purposes). public class DrawingSpriteScreen extends BaseScreen { private Texture _sourceTexture = null; float x = 0, y = 0; @Override public void create() { _sourceTexture = new Texture(Gdx.files.internal("data/character.png")); } . . } During rendering of the screen, if the user touched the screen, I grab the coordinates of

libGDX project can't load library liblwjgl.dylib

五迷三道 提交于 2019-12-03 11:30:56
A new libGDX project can't load the library liblwjgl.dylib when running the desktop project. Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /var/folders/4l/nsj9j4xj51g8h_6y_ndpnmc80000gn/T/libgdxChristian/3741154320/liblwjgl.dylib at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1798) at java.lang.Runtime.load0(Runtime.java:809) at java.lang.System.load(System.java:1080) at org.lwjgl.Sys$1.run(Sys.java:70) at java.security.AccessController.doPrivileged(Native Method) at org.lwjgl.Sys.doLoadLibrary(Sys.java:66) at org.lwjgl.Sys.loadLibrary(Sys.java:95) at

Is it possible to disable frame-limiting in libGDX?

£可爱£侵袭症+ 提交于 2019-12-03 10:28:01
More specifically, a desktop libGDX-LWJGL application. There are configurations options to disable CPU syncing as well as vsynching, but regardless the application runs at 60fps. This is fine for all practical uses - but out of curiousity if nothing else, I'd like to see how high the framerate could go. Aaron Mahan Rode Hyde 's answer is no longer correct due to changes in the library. Try this: LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.vSyncEnabled = false; // Setting to false disables vertical sync config.foregroundFPS = 0; // Setting to 0 disables

Libgdx学习笔记:分享自己写的异步加载

。_饼干妹妹 提交于 2019-12-03 09:37:17
从需求说起: 解析xml,json文件等耗时的操作,如果放到绘制线程,或者初始化里面,会导致画面卡顿一下,让人看起来不爽,这时候就想能不能异步加载一下。 查看Libgdx的AssetManager发现里面用到了AsyncExecutor,AsyncTask,AsyncResult相关异步线程池。 简单介绍下: 【AsyncExecutor】 在一个独立的线程里面,异步执行 AsyncTask实例。不需要使用的时候,调用dispose()进行释放。 看内部源码,实际使用了java的线程池Executors.newFixedThreadPool来管理的。 简单说是处理 AsyncTask的容器。 【 AsyncTask 】为接口,可根据实际情况实现成自己的Task。 提交任务给一个AsyncExecutor,返回类型为T的结果。 【AsyncResult】 AsyncExecutor.submit(AsyncTask)返回的结果。 isDone()方法,代表任务是否处理完毕。 ================================================================= 上代码: CHAsyncTask 抽象任务类 CHAsyncManager异步管理中心,最好放在Game里面初始化一次,并且在render()中调用update()方法。

json file for libgdx Table

匿名 (未验证) 提交于 2019-12-03 09:17:17
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to make a Table that has a Skin based on libgdx's default LabelStyle and BitmapFont through the use of a json file. (this file is supposed to hold the references of these two objects) In doing this I am getting some unclear errors. For instance: Exception in thread "LWJGL Application" com . badlogic . gdx . utils . SerializationException : Error reading file : ui / uiskin . json at com . badlogic . gdx . scenes . scene2d . ui . Skin . load ( Skin . java : 96 ) at com . badlogic . gdx . scenes . scene2d . ui . Skin .<

How should I render a 2D flashlight effect?

£可爱£侵袭症+ 提交于 2019-12-03 08:54:22
I'm trying to make a flashlight effect in my 2D game. My flashlight is represented as a line segment extending from the entity at a specific angle. The flashlight can point in any direction. The flashlight also varies in intensity (length of the flashlight beam). I'm have a problem trying to figure out the best (easiest?) and most flexible way to render the flashlight effect. Particularly with the tiled map. I can think of two methods. But I have no idea to implement them: ONLY draw a conical/circle-segment part of the tiled map covering the screen with a black texture, and with code punching

LibGDX FreeType font blurry

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm generating my font dynamically using the screen height percentage and set percentages (Obviously multiplied by density's in the future. Some notes. I'm reading from an OTF file. Using the latest version of LibGDX (Version 1.2.0) I have the following problem: (Large breaks in the font and looks very blurry, but only on medium . Large and small look very sharp) My Preset font sizes: //Font sizes, small, med, large as a percentage of the screen. public static float FONT_SIZE_LARGE = 0.175f, FONT_SIZE_MEDIUM = 0.06f, FONT_SIZE_SMALL = 0.04f;

Libgdx - Check if a key is being held down?

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using the java libgdx game library and im curious if I can tell if a key is being HELD, not pressed and let go. I need to know this because I'm going to play a shorter mp3 file if it is just pressed and a longer one if it is held. 回答1: Yes, you can easily check they either via Gdx.input.isKeyPressed(Input.Keys.XXX) or by implementing an InputProcessor . public class MyInputProcessor implements InputProcessor { public boolean keyPressed; @Override public boolean keyDown(int keycode) { if (keycode == Input.Keys.XXX) { keyPressed = true; }