libgdx

Creating an Android save file on the local storage of the device?

谁说胖子不能爱 提交于 2019-12-25 08:13:53
问题 I'm using Libgdx for a game on Android, and i want to create a save file on the local storage of the user's phone, and i'm wondering how would i go about doing that. Some of the documents I have read such as here: https://developer.android.com/guide/topics/data/data-storage.html#filesInternal have been quiet vague, and I don't really understand what is going on, or can make the example work in my own game. Is there a feature for this in Libgdx itself? 回答1: in libgdx for storing the data we

Java - Libgdx : Keep actor's position even screen's resolution changes

♀尐吖头ヾ 提交于 2019-12-25 08:09:13
问题 issue is next one: my game is built for 1080x1920 pixels screen but if I run it in other resolutions my actors' position is switching. Some pictures if you haven't understood: ~> original resolution ~> other resolution I looked for an answer for days in Google, Stackoverflow, forums, couldn't find the right answer for my problem, here's my code: public class PlayScreen implements Screen { private Main game; private Stage stage; Music music; Sound sound; private class MenuGame extends Actor {

Is referencing Styles, fonts and images from static class bad?

若如初见. 提交于 2019-12-25 07:56:29
问题 I've read a lot about different pitfalls of using static classes, so I never really bothered using one. However I could see major advantages for me in creating a static class that holds all my styles, images, fonts etc. For easy referencing. Would this be bad for performance or bad design? To help explain what I mean I have some code, this is from the static class: button2Style = new TextButtonStyle(); button2Style.up = new NinePatchDrawable(buttonAtlas.createPatch("button2")); button2Style

Libgdx, Android, how to drag and move a texture

好久不见. 提交于 2019-12-25 07:14:38
问题 currently the method I used is to detect whether touch position (Gdx.input.getX() & Y()) is in the area whether the object texture is. If so I setPosition of the object texture to the mouse position as center. While this work but it is not robust. Because if my finger move faster than the update, as soon as the touched position is outside texture bound. It won't update any more. There must be a more reliable way and please advice. Essentially, I want to touch on the texture and drag the

JSON parse and encoding with generic types

淺唱寂寞╮ 提交于 2019-12-25 06:54:28
问题 I have an generic array of objects: static Array<Level> allLevels = new Array<Level>(); Now I want to encode it to json like this: Json json = new Json(); String levelsJsonString = json.prettyPrint(allLevels); The problem occurs when I'm trying to reverse this process: allLevels = json.fromJson(Level.class, levelsJsonString); It is raising that Array and Level are incompatible types. How to do this? 回答1: As far as I know there's always problem with passing generic type class to a json

How to select and deselect a Rectangle/texture properly on click

那年仲夏 提交于 2019-12-25 06:47:09
问题 A video of the problem itself : https://www.youtube.com/watch?v=cJfFIB3baAg I know there's a simple way to do this with scene2d but i chose to make this project with Rectangle and Texture variables, that means I have 20 Textures(1 to 9 with blank background and 1 to 9 with green blackground as shown in matrix[0][0]) and 20 Rectangles , which each one represents one of the Texture variables created. Like you see, the square[0][0] is selected at this very momment. What I want to do Is, by

How to render a sprite 2 seconds after a collision

邮差的信 提交于 2019-12-25 06:42:22
问题 I want to draw/render my sprite 2 seconds after a collision. How can I make it ? If i do in that way the render add a new ButtonOrange immediately. @Override public void render(SpriteBatch batch) { relation.add(new ButtonOrange(coordinates,text); relation.get(0).update(); relation.get(0).draw(batch); if(relation.get(0).collission() == true) relation.remove(0); } 回答1: You can use a temporary timer variable to store time elapsed since collision and if its greater than 2 second, draw that sprite

Changing FixtureDef properties Java Libgdx

让人想犯罪 __ 提交于 2019-12-25 06:34:14
问题 I use a Factory Pattern for creating Box2D bodies in my game. Here is the code that creates the bodies: public static HashMap<String, Object> createAndGet(Vector2 position, Vector2 dimensions, BodyType type, boolean isCircle){ HashMap<String, Object> bodyObjectsHash = new HashMap<String, Object>(); BodyDef bodyDef = new BodyDef(); bodyDef.type = type; bodyDef.position.set(new Vector2(position.x, position.y)); Body body = EntityManager.createBody(bodyDef, dimensions); FixtureDef fixtureDef =

Parsing json into a nested ArrayList in libgdx

守給你的承諾、 提交于 2019-12-25 05:29:10
问题 I was using Jackson for all my json serialisation and deserialisation, but I'm trying to get my game working with GWT now so I'm moving over to the libgdx json parsing libraries. Everything seems ok so far except this HashMap<String, ArrayList<HighScoreEntry>> high_scores = new HashMap<String, ArrayList<HighScoreEntry>>(); The ArrayList within the hashmap is being created as a array of JsonValue rather than an array of HighScoreEntry. Can someone explain how I work around this? I know about

Animating the sprite array created from texture atlas

十年热恋 提交于 2019-12-25 04:13:32
问题 I have created a sprite array from texture atlas like this. playerSprite = atlas.createSprites("player"); Inside texture atlas, player regions are named as player01 , player02 and player03 . playerAnimation = new Animation(0.5f, playerSprite); playerAnimation.setPlayMode(PlayMode.NORMAL); and I rendered it like this. batch.draw(playerAnimation.getKeyFrame(animTime,true), ninja.getX(),ninja.getY(), ninja.getWidth(),ninja.getHeight()); When I execute, this throws an error. "Exception in thread