libgdx

Invoke object constructor when deserializing json using libgdx

廉价感情. 提交于 2019-12-11 03:29:09
问题 How come my objects constructor for player is not called during deserialization? Is there a way to invoke the constructor using this approach? Load json into java object using com.badlogic.gdx.utils.Json .. LevelModel ld = new Json(). fromJson(LevelModel.class, Gdx.files.internal("levels/level1.json")); setLevel(new Level(ld)); Heres my JSON .. { "gravity": { "x": 0.0, "y": 0.0 }, "sounds": [ BGMUSIC ], "player": { "maxSpeed": 10.0 } } LevelModel.java looks like this .. public class

Ad is not visible. Not refreshing ad

爷,独闯天下 提交于 2019-12-11 03:20:03
问题 I have made a free android game and I wanted to add a banner to it. I followed this tutorial and I don't know why it won't work. When I run my game on the emulator in LogCat I see a message "Ad is not visible. Not refreshing ad." and when I install the game on my phone I also don't see any ads. Here is my main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android

Dialog's object position Libgdx

假如想象 提交于 2019-12-11 03:16:33
问题 I have a Dialog : Dialog dialog=new Dialog("",style); dialog.setSize(400, 500); dialog.setPosition(Gdx.graphics.getWidth()/2-200, Gdx.graphics.getHeight()/2-300); I added a two button in it: dialog.button(stopButton); dialog.button(goButton); My problem is that I can not change the position of buttons, not even if the imposed manually the buttons remain in the same position. how could I do to solve the problem? Thank you 回答1: The buttons of a libgdx dialog get added to the ButtonTable of the

Libgdx,change pitch in Music

时光毁灭记忆、已成空白 提交于 2019-12-11 03:12:48
问题 I want to implement a cool effect, when there is an explosion the music gets slightly slower for a moment. The Music class of libgdx doesn't allow changing the pitch of the sound, I tried using the Sound class instead of the Music to play my music but its very slow at loading the files ( 5 sec for a 5 mb file, on Desktop! ). So, the question is if there is a way to workaround this, or if there is an external library, that works both on desktop and android and can work along with libgdx. 回答1:

Drawing shapes as textures in LibGDX

自古美人都是妖i 提交于 2019-12-11 03:09:54
问题 I'm creating menus in my game specially rectangles with rounded corners and borders. I can do this with a shape renderer but I cannot mix shape renderer and sprite batcher. At the moment my resolution seems to be using large shapes as PNG's and scaling them BUT on a lot of devices this produces blurry corners. I've read my tutorials on Meshes, shaders, using the shape renderer after the sprite batch (complication layer and performance impact), 9-patch (Border goes blurry, can't do gradients

Angle between two points and calculating the rotation

好久不见. 提交于 2019-12-11 03:05:05
问题 so I'm currently programming a little game in Java with libGDX. I want the players texture to directly rotate to the mouse position. Unfortunately my code doesn't work, and I have absolutely no idea why not. So, I call this method in the Update method of the player: private void CalculateRotation() { rotation = Position.angle(input.getTranslatedMousePos()); } The Position is just a Vector2 with the players position. I get the translatedMousePos like this: public Vector2 getTranslatedMousePos(

Java: Passing an instance of “this” during instantiation [closed]

馋奶兔 提交于 2019-12-11 02:57:00
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . myClass1: public class myClass1 { public myClass2 myclass2; public void createsecondclass (String[] args) { myclass2 = new myClass2(this); myclass2.dosomething(); } myClass2: public class myClass2 { public myclass1; public myClass2(myClass1 myclass1) { this.myclass1 = myclass1; }

Draw font on top of box2d body

浪子不回头ぞ 提交于 2019-12-11 02:55:13
问题 How can I draw text (font) on top of my static box2d body? Background: Im able to draw sprites on top of bodies correctly. I do this by having a box2dSpriteBatch which is projected on box2dCamera like so box2dSpriteBatch.setProjectionMatrix(box2dCamera.combined); And then simply rendering the sprite in the correct spot using getPosition of the body. But if i try the same way for fonts, unfortunately it scales incredibly large, and if i try to scale the font down it doesn't appear. So im

Where can I access Gdx.files.local()?

拥有回忆 提交于 2019-12-11 02:51:09
问题 I have a pre-made json file that I want to test out. This Json file will be modified so I want to read/write. I noticed that internal is read-only. So I want to save my Json file in the local storage(manually through eclipse or OS(windows 8)) such that I can access through files.local(). Does anyone know the address of the local storage defined by libgdx? So that I can save my pre-made Json file? This is for testing only! If there is a better way for me to test out my json file (read/write)

java.lang.NoClassDefFoundError when running libgdx sample gdx-invaders for desktop

心已入冬 提交于 2019-12-11 02:48:24
问题 I'm building libgdx's gdx-invaders sample. There are two projects: gdx-invaders - the base project, which runs as a desktop Java application gdx-invaders-android project - depends on gdx-invaders, and runs as an Android application I'm new to Eclipse, but based on the best tutorials I could find, took the appropriate steps to get these two projects referencing the appropriate libraries (gdx.jar, etc.), and to get them using Android 2.2. I also tried basic fixes like cleaning before building,