libgdx

How to change Sprite texture to Animation

青春壹個敷衍的年華 提交于 2019-12-02 11:37:57
I have a Sprite that spawns every second, what I wan't to do is change the sprite texture to animation, and the when it's touched it will be back to a normal texture. public void draw(SpriteBatch batch){ enemyIterator=enemies.iterator(); //arraylist iterator boolean touched=Gdx.input.justTouched(); float touchX=Gdx.input.getX(); //rendering and making the current sprite move while(enemyIterator.hasNext()){ Sprite sprite=enemyIterator.next(); sprite.draw(batch); sprite.translateY(deltaTime*movement); //detecting if the screen is touched and if the inputX is inside of the sprite. if(touched=

How to decrease loading time of all Assets in libgdx

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:14:02
问题 I am making a game in libgdx. I use AssetManager class to load assets. When I start my game its takes more time to load assets on android device and show black screen at that time.How can I resolve that problem. 回答1: Well it will show a blank screen. In order to solve this problem you can render something while loading of assets is done and as the loading is done you switch to menu screen. import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx

Android Studio LibGDX Gradle Sync Error

こ雲淡風輕ζ 提交于 2019-12-02 10:35:04
问题 After trying to run the gradle sync I get this error. I'm not sure if this is somehow related to libgdx or is it just a Gradle problem. Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in

LibGDX very strange bug - objects are disappeared

风流意气都作罢 提交于 2019-12-02 10:08:04
问题 When I was creating my first tiled map creator in libGDX , I noticed a very strange bug. I creating grid of objects like this: private static final int GRID_WIDTH=2400; private static final int GRID_HEIGHT=2400; private static final int CELL_SIZE=60; so you can see there are 2400/60x2400/60 objects or cells. I am creating my map like this: private void createMap(){ cells = new Cell[GRID_WIDTH/CELL_SIZE][GRID_HEIGHT/CELL_SIZE]; for(int i=0;i<GRID_WIDTH/CELL_SIZE;++i){ for(int j=0;j<GRID_HEIGHT

How to build a ResourceManager in libGDX with AssetManager

白昼怎懂夜的黑 提交于 2019-12-02 10:07:15
I want use non static AssetManager In my android game? I have many levels. How should I use AssetManager? I should create for every level a separate AssetManager? Because if I create one AssetManager, it will load all textures, etc, in first screen. You should create one AssetManager in your main class which load all assets at the startup of the application. Then for each level you should create a different screen or use one screen, depending on your game. Then you pass a reference of the AssetManager to every new screen instance you create (for the screen to access it's assets). For example:

LibGdx texture drawn as inverse of what #getTextureData gives

梦想与她 提交于 2019-12-02 09:50:19
I've been trying to resolve this issue I have been having with displaying a texture correctly on my libgdx desktop program. I have an Orthographic camera with which when I set as: camera.setOrtho(false); I get this image: And when I set it as: camera.setOrtho(true); I get this image: The red image is drawn with a SpriteBatch: batch.draw(texture, x, y, width, height); While the white image is drawn from individual points plotted based on if their alpha value was 1. TextureData td = texture.getTextureData(); td.prepare; Pixmap map = td.consumePixmap(); for (int i = 0; i < map.getWidth(); i++)

Box2d libgdx, a bit confused about the pixels to meters stuff

社会主义新天地 提交于 2019-12-02 09:42:12
So I understand the concept. The idea is that box2d more or less works in meters, so you need to do a conversion from pixels to it. Makes sense. I was following the tutorial/intro to box2d here . It mentions to do the conversion and gives you some example amounts to use. Now, that's all well and good, but I find when I'm using such techniques, the debugger box doesn't seem to render where they should. The collision does work as expected however. In my GameScreen class, here's how I initialize the ground: ground = new BodyDef(); // set the position half way up the ground ground.position.set(0

Status of the Loading the TextureAtlas

ぐ巨炮叔叔 提交于 2019-12-02 09:41:38
I am using the TextureAtlas in my LibGdx based game. As the size of the Atlas increases the loading time increases hence there is a delay in showing the animations that I have setup in the game. Hence I wish to get the status of the loading process of my TextureAtlas. 1. Anyway to get the status ? 2. Any Listener ? You can take for example, asset that have been loaded with this method, yourAssetManage.getLoadedAssets () this method return an int indicating the number of loaded assets Gdx.app.log("asset loaded :", ""+yourAssetManger.getLoadedAssets()); if (yourAssetManger.update()) { if (Gdx

LibGDX - Conditionally use java or android classes

穿精又带淫゛_ 提交于 2019-12-02 09:28:47
I'm using bezier curves in my libgdx project. I was testing the desktop version using java.awt.geom with GeneralPath but when I went to test on android, it raised an error saying that I can't import java.awt . Android have corresponding classes for GeneralPath , Point2D etc so my question is how can I use those classes in their respective environments? Android does not have an AWT implementation, so references to those classes won't work on Android. (On the desktop you're getting those classes from the JDK.) Technically, you can put code that depends on AWT in your desktop Libgdx backend, and

How to draw on just a portion of the screen with SpriteBatch in libgdx?

為{幸葍}努か 提交于 2019-12-02 09:20:56
问题 When I do this: SpriteBatch spriteBatch = new SpriteBatch(); spriteBatch.setProjectionMatrix(new Matrix4().setToOrtho(0, 320, 0, 240, -1, 1)); spriteBatch.begin(); spriteBatch.draw(textureRegion, 0, 0); spriteBatch.end(); SpriteBatch will draw the textureRegion onto the coordinate system 320-240 that I have specified to the whole screen. Say I want to draw with the same coordinate system 320 240 but only on the left half of the screen (which means everything will be scaled down horizontally