libgdx

How do I detect if a sprite was touched in Java libGDX?

白昼怎懂夜的黑 提交于 2019-11-26 23:10:55
问题 In the past few days I've been porting my game (Apopalypse) to the Android Mobile platform. I've did a quick search on Google of sprite touch detection but didn't find anything helpful. Each balloon will pop once touched and I just need to detect if it's touched. Here's my balloon spawning code: Rendering (x, y, width, and height are randomized): public void render() { y += 2; balloon.setX(x); balloon.setY(y); balloon.setSize(width, height); batch.begin(); balloon.draw(batch); batch.end(); }

How to create a button in Libgdx?

本小妞迷上赌 提交于 2019-11-26 22:36:03
问题 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. 回答1: A button is simply an actor in libgdx. To render an actor you use a stage that contains all the actors of the screen,

Libgdx Box2D pixel to meter conversion?

白昼怎懂夜的黑 提交于 2019-11-26 21:43:16
问题 When trying to program a game using Box2D, I ran into a problem with Box2D. I filled in pixel numbers for the lengths of the the textures and sprites to create a box around it. Everything was at the right place, but for some reason everything went very slowly. By looking on the internet I found out that if you didn't convert pixels to meters box2d might handle shapes as very large objects. this seemed to be a logical cause of everything moving slowly. I found similar questions on this site,

Error at building model of new Gradle project for libgdx

非 Y 不嫁゛ 提交于 2019-11-26 19:45:39
问题 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

Failed to resolve: com.google.android.gms:play-services in IntelliJ Idea with gradle

雨燕双飞 提交于 2019-11-26 17:59:11
问题 I'm trying to add google play services to my libGDX project in IntelliJ Idea. I've followed the setup guide here: https://developers.google.com/android/guides/setup which looks pretty straightforward. I just added those lines to my build.gradle in the corresponding section, so things look now like: project(":android") { apply plugin: "android" apply plugin: 'com.android.application' configurations { natives } dependencies { compile project(":core") compile "com.badlogicgames.gdx:gdx-backend

Converting Android Bitmap to LibGdx's Texture

主宰稳场 提交于 2019-11-26 16:56:58
问题 i am trying to convert bitmap into a libGDX Texture by converting: Android Bitmap to byte[] byte[] to libGDX Pixmap libGDX Pixmap to libGDX Texture The problem I am facing is that the bitmap which is converted to texture is drawing the sprite sheet from texture packer that is in assets folder public void onByteArrayOfCroppedImageReciever(byte[] bytes) { try { pmap=new Pixmap(bytes, 0, bytes.length); tex=new Texture(pmap); face=new Sprite(tex); // game.setScreen(new GameScreen(game, batcher,

Using unProject correctly in Java Libgdx

空扰寡人 提交于 2019-11-26 16:45:47
问题 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();

LibGDX: How to make tiled map tiles clickable?

狂风中的少年 提交于 2019-11-26 16:32:18
问题 How can I add click listeners for the tiles from tiled map so that when you select a tile with the mouse it becomes highlighted? 回答1: That's not supported directly by libGDX as the TiledMap stuff is only for rendering. You could easily create a Stage though, which will act as some kind of overlay-input-layer for your TiledMap. Just create an Actor for each tile which has the same size as position as that tile. Then you are able to add EventListener s to those actors to be able to recognize

How get a string width in Libgdx?

时光毁灭记忆、已成空白 提交于 2019-11-26 16:07:35
问题 I wonder know how to get the width of my string in pixels 回答1: BitmapFont API < 1.5.6 To mesure the width of a String you use your Font and get the bounds of the String , you are going to draw. BitmapFont.getBounds(String str).width BitmapFont API You can get the height to for the right offset for drawing too. Just replace width with height. In addition for multiline texts use getMultiLineBounds(someString).width to get the bounds. BitmapFont API >= 1.5.6 The BitmapFont API changed in 1.5.7

“File not found” when running new LibGDX project

£可爱£侵袭症+ 提交于 2019-11-26 15:55:01
I trying to learn LibGDX, I install all the software listed here with a new Eclipse 4.3 on a fresh formatted mac OS X Maverick. Everything goes smooth, after a reboot, I download, and execute the gdx-setup.jar, fill the form, and import into Eclipse. No error, no warning, when I try to run the desktop. (Right click the desktop project, Run As -> Java Application). I got this error Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: badlogic.jpg at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140) at com.badlogic.gdx.graphics.glutils