libgdx

libGDX : How check if the actor exist on stage or not

纵饮孤独 提交于 2019-12-23 16:17:46
问题 How can I check the actor is removed or not on stage ? like this: if(actor.isRemoved) { // enter code here } 回答1: From the Documentation: getStage public Stage getStage() Returns the stage that this actor is currently in, or null if not in a stage. So you can use it like: if(actor.getStage() == null) { //actor not on stage } 来源: https://stackoverflow.com/questions/33270598/libgdx-how-check-if-the-actor-exist-on-stage-or-not

Static sprite batch?

两盒软妹~` 提交于 2019-12-23 15:33:09
问题 As my research goes everywhere it's said that we should only use one sprite batch per instance. But what if i set sprite batch to static in class which controls the game (calls different screens etc). When i have tryed this its working like charm, but is that a good practice or it may result some problems in future. Then if it could be done can i also share stage and shape renderer? note: the main reason why i am trying to go with that "static batch technique" is that java crashes when i try

how to get stage in the center in libgdx?

早过忘川 提交于 2019-12-23 12:34:57
问题 My image is of size 720x480 and stage is of same size. The boolean parameter, whether to stretch the stage or not is kept false, so that aspect ratio is maintained, now the problem i am getting that a black area is shown on either side of the screen I want my scene to be centered. The link below refers a file, which shows the problem more clearly, that image is aligned to the bottom left i want it to be centered so that the black area is divided equally on top and the bottom. what is the

How to scroll a ScrollPane in code?

这一生的挚爱 提交于 2019-12-23 12:15:27
问题 I’m trying to make a scrollwheel component like this in LibGDX: I’m using ScrollPane since it has input and fling handling built in. I have an image for the scrollwheel that is divided into 14 sections, the scrollpane itself is two sections shorter so that there will be one section on the right and left sides that it can scroll to in either direction. Once the scroll position reaches the end in either direction I want to reset the scroll position back to the center. Doing this over and over

How to pause and resume in LibGDX using the back key?

删除回忆录丶 提交于 2019-12-23 12:02:12
问题 I'm creating a game using LibGDX. Now I have two problems. First, I'm trying to catch back key so that the game will pause. I'm already calling the Gdx.input.setCatchBackKey(true) method in my Game class. Here is the code : public class CvSGame extends Game { public Preferences prefs; @Override public void create() { Gdx.input.setCatchBackKey(true); prefs = Gdx.app.getPreferences("game_pref"); //setScreen(new SplashScreen(this)); //setScreen(new HomeScreen(this)); //setScreen(new GameScreen

Programs run fine with LibGDX -desktop but not LibGDX - Android?

…衆ロ難τιáo~ 提交于 2019-12-23 11:28:27
问题 So I have just set up Eclipse to work with LibGDX using Gradle. After I installed I noticed there was a problem with the Android package, there was a red cross next to the package. When I opened it further there was a red cross next to src then com.myname.game.android and then in AndroidLauncher.java. When I opened the AndroidLauncher.java, this was the code I got: package com.faturbansloth.game.android; import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication;

Programs run fine with LibGDX -desktop but not LibGDX - Android?

别来无恙 提交于 2019-12-23 11:25:04
问题 So I have just set up Eclipse to work with LibGDX using Gradle. After I installed I noticed there was a problem with the Android package, there was a red cross next to the package. When I opened it further there was a red cross next to src then com.myname.game.android and then in AndroidLauncher.java. When I opened the AndroidLauncher.java, this was the code I got: package com.faturbansloth.game.android; import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication;

Nesting ShapeRenderer.begin/end in SpriteBatch.begin/end

人走茶凉 提交于 2019-12-23 09:21:18
问题 Is it possible to draw shapes by using ShapeRenderer between SpriteBatch begin and end calls. I have tried but no result, only SpriteBatch textures are drawn, no shape is on the scene. Sample code is as followed below : shapeRenderer.begin(ShapeType.FilledCircle); shapeRenderer.setColor(0f, 1f, 0f, 1f); shapeRenderer.filledCircle( 100, 100, 100); shapeRenderer.end(); I have a orthographic camera created by these commands : camera = new OrthographicCamera(1, Gdx.graphics.getHeight() / Gdx

How to change libgdx different window size?

廉价感情. 提交于 2019-12-23 06:58:31
问题 How to change size in libgdx-android-desktop? I am confuse on window sizeing and not sure how to solve this problem. So for desktop window i want 500x500 but with android i want full screen so i cant hard code it. For some reason ANDROID_WIDTH is always equal to WINDOW_WIDTH. int WINDOW_WIDTH = 500; int WINDOW_WIDTH = 500; public void create() { if (Gdx.app.getType() == ApplicationType.Android) { int ANDROID_WIDTH = Gdx.graphics.getWidth(); int ANDROID_HEIGHT = Gdx.graphics.getHeight();

Sound button to make sound ON or OFF does not changing button image

♀尐吖头ヾ 提交于 2019-12-23 04:36:38
问题 I have a sound button in my menu screen.It has two images.one is normal and other is checked(indicating sound is OFF). I am using a boolean variable to get the state of this button.If it is true,sound will play else sound will be OFF.I am using it to control in-game sounds. public boolean soundBool=true; created soundButton like this:Here soundTexture1 is normal image(ON) and soundTexture2 has a cross mark(OFF). private void drawSoundButton() { soundButton = new ImageButton(new