libgdx

Using unProject correctly in Java Libgdx

一世执手 提交于 2019-11-27 22:14:42
I want to make a button clickable, but it isn't working - it seems like I need to use unproject() but I can't figure out how. The code in question is: Texture playButtonImage; SpriteBatch batch; ClickListener clickListener; Rectangle playButtonRectangle; Vector2 touchPos; OrthographicCamera camera; @Override public void show() { playButtonImage = new Texture(Gdx.files.internal("PlayButton.png")); camera = new OrthographicCamera(); camera.setToOrtho(false, 800, 480); batch = new SpriteBatch(); playButtonRectangle = new Rectangle(); playButtonRectangle.x = 400; playButtonRectangle.y = 250;

Circle and Polygon Collision with Libgdx

荒凉一梦 提交于 2019-11-27 20:52:50
Is there a way in Libgdx to verify a collision between a Polygon and a Circle? I saw the Intersector class but only found collision test for Circle and Rectangle. What about any other Polygon? If I need to do it manually, what's the best way to do that using Libgdx? So, I managed to create a collision test method between a Circle and a Polygon. At least, it works for me. Here's the code: public boolean overlaps(Polygon polygon, Circle circle) { float []vertices=polygon.getTransformedVertices(); Vector2 center=new Vector2(circle.x, circle.y); float squareRadius=circle.radius*circle.radius; for

How to put properly a libgdx application inside swing application?

 ̄綄美尐妖づ 提交于 2019-11-27 20:16:30
I'm creating a level editor for my game, and I ave a problem using LwjglCanvas with a JFrame. I use a JFrame (not a LwjglFrame) to keep engine and level editor as independent as possible. I have two JARs: WorldEditor.jar, and GameEngine.jar. Inside WorldEditor, I have a button called "test", that is suppose to load GameEngine.jar (if not already loaded) and launch (resart it if already loaded) it into the application main frame. Actually, what I do is injecting the WorldEditor game container (a JPanel inside the JFrame for example) to the game app, and use Gdx.app.postRunnable to add the

Error at building model of new Gradle project for libgdx

你离开我真会死。 提交于 2019-11-27 19:07:45
I installed Gradle in eclipse and want to import a libgdx Gradle project. But when i click on "Build Model" button, i have an error at about 50% of the loading bar. Here is the problem : > Plug-in: org.springsource.ide.eclipse.gradle.core Severity : error > Message : org.eclipse.osgi.internal.framework.EquinoxConfiguration$1 > Exception Stack trace : java.lang.reflect.InvocationTargetException > at > org.springsource.ide.eclipse.gradle.core.util.GradleRunnable.run(GradleRunnable.java:92) > at > org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122) > Caused by:

LibGDX 0.9.9 - Apply cubemap in environment

元气小坏坏 提交于 2019-11-27 18:58:55
问题 I am using LibGDX 0.9.9. I am trying to render cubemap and fog. So my code snippet below: 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

libGDX Alert Dialog

做~自己de王妃 提交于 2019-11-27 18:16:07
问题 I have used code below: AlertDialog.Builder bld; if (android.os.Build.VERSION.SDK_INT <= 10) { //With default theme looks perfect: bld = new AlertDialog.Builder(AndroidLauncher.this); } else { //With Holo theme appears the double Dialog: bld = new AlertDialog.Builder(AndroidLauncher.this, android.R.style.Theme_Holo_Dialog_MinWidth); } bld.setIcon(R.drawable.ic_launcher); bld.setTitle("Exit"); bld.setMessage("Are you sure you want to exit?"); bld.setNegativeButton("Cancel", new DialogInterface

LibGDX inside Android Activity

陌路散爱 提交于 2019-11-27 17:52:22
问题 I'm in the middle of developing a small app for Android using the Android UI and activities for the most part of the interaction, however one key aspect requires the use of LibGDX (using 3D models and physics). I want to be able to click a button in my app (my "Activate" class) which will open the "AndroidApplication" class (my "Bobble" class) that initializes and runs all the LibGDX code. My problem is that I can't use an "Intent" to start an AndroidApplication class (only an Activity as far

How to create a button in Libgdx?

谁都会走 提交于 2019-11-27 17:43:27
I want to create a button that changes when the user hovers it, or clicking it. I created the following variable Button buttonPlay = new Button(); I don't know what to do now, how to load the images? How to write text into the button? How to implement the events / effects (hover, click)? It would be very helpful if someone could write some example code for a button. A button is simply an actor in libgdx. To render an actor you use a stage that contains all the actors of the screen, renders them and updates them. I assume you want a button with text, so you should use the class TextButton and

LibGDX - Application crashes when call TiledMapRenderer.render()

余生长醉 提交于 2019-11-27 16:38:24
问题 @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(); } Here is what I get when launching the desktop version : Exception in

Multiple cameras in libgdx ( probably similar in other frameworks )

不羁的心 提交于 2019-11-27 16:29:34
问题 I have been trying to solve this problem for two days and I have given up trying to find an existing solution. I have started learning libgdx and finished a couple of tutorials. And now I have tried to use all that I have learned and create a simple side scrolling game. Now, I know that there are libgdx examples of this, but I haven't found a one that incorporates Box2d with scene2d and actors as well as tiled maps. My main problem is with the cameras. You need a camera for the Stage (which