libgdx

How to change the alpha of a bitmap font in libgdx

China☆狼群 提交于 2019-12-05 10:42:25
I want to make a message box that fade when you accept but I don't know how to change the alpha of a font, here is how I do my font: white = new BitmapFont(Gdx.files.internal("data/font/whitefont.fnt"),false); white.setUseIntegerPositions(false); white.setScale(0.025f); white.draw(batchHUD, message.nom+":", 1000*0.1f+(1000*0.8f*0.3f), 625*0.1f+(1000*0.8f*0.625f*0.5f*0.1f)+1000*0.2f); Can anyone help me ? :) I'm sorry for my english, it's not my native language. white.setColor(1, 1, 1, <alpha>); This will change the alpha of the font for all following draws. So you would probably want to set it

How correctly save game progress via libGDX Preferences on Android devices?

若如初见. 提交于 2019-12-05 10:40:40
I am using next code. This code work fine on desktop version, but on Android device does not. return Gdx.app.getPreferences(PREFS_NAME) always is null. Why? Where I could make mistake? import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Preferences; public class BeatlesPreferences { // constants private static final String PREF_VIBRO = "vibro"; private static final String PREF_MUSIC_ENABLED = "musicenabled"; private static final String PREF_SOUND_ENABLED = "soundenabled"; private static final String PREFS_NAME = "my_app"; public BeatlesPreferences() { } protected Preferences getPrefs() {

Libgdx Orthographic Camera initial position

北城以北 提交于 2019-12-05 09:58:18
I would like the camera to be positioned correctly but I am getting the result below: It seems like when I resize the window, the map does not get rendered properly. Why does that happen? Code: public void render(float delta){ Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); camera.update(); mapRenderer.setView(camera); mapRenderer.render(background); mapRenderer.render(foreground); shapeRenderer.setProjectionMatrix(camera.combined); //draw rectangles around walls for(MapObject object : tiledMap.getLayers().get("walls").getObjects()){ if(object instanceof

Libgdx Scene2d - Set actor ( TextField ) padding?

烈酒焚心 提交于 2019-12-05 09:38:01
i have been having trouble setting padding or something similar to an actor. Cant figure out the way. I guess that I must add something in the skin maybe? I have this TextField: textboxskin = new Skin(); textboxskin.add("textfieldback", new Texture("data/textfieldback.png")); textboxskin.add("cursor", new Texture("data/cursortextfield.png")); textboxskin.add("selection", new Texture("data/selection.png")); textboxskin.add("font", font); TextFieldStyle textfieldstyle = new TextFieldStyle(); textfieldstyle.background= textboxskin.getDrawable("textfieldback"); textfieldstyle.disabledFontColor

Multi-colored text in libgdx

夙愿已清 提交于 2019-12-05 09:19:50
I found out there is a new component in LibGDX in nightly builds - TextArea which is part of the scene2d.ui package. It's nice to have a component like this, very easy to use, but what I'm missing is some support for a multi-colored text. I want to highlight some keywords in a text with a different color but I don't know how to do it with current api. There is one method in BitmapFontCache class: public void setColors (Color tint, int start, int end) Javadoc for this method says following: Sets the color of the specified characters. This may only be called after setText(CharSequence, float,

Game crash if interrupted while Splash Screen is on - LIBGDX

假如想象 提交于 2019-12-05 08:26:49
I have a splash screen and a menu screen class that loads all my texture atlases and skins for the menu and processes lots of stuff. If I put the constructor for the menu screen in the SplashScreen constructor or in the create() method of my main game class (MyGame class) then it would pass a lot of time with no splash screen render image on the phone while the whole stuff loads so I have delayed the loading of the menu class to the second frame render (gets called in the SplashScreen render method in the second frame); I simply check if I passed the first frame then I call a method on the

Event not delivered to listener

眉间皱痕 提交于 2019-12-05 08:14:00
I have a libgdx game that uses scene2d for the UI. I have several ImageButton instances with its own ClickListener . On some devices (only seen it on Samsung Galaxy S3 and Samsung Galaxy S4 Active so far) there is a problem with the event not being delivered unless one clicks twice quickly. Every time a click fails something like the following is logged: 04-22 16:10:09.678: D/InputReader(728): Input event: value=1 when=20897610551000 04-22 16:10:09.678: I/InputReader(728): Touch event's action is 0x0 (deviceType=0) [pCnt=1, s=0.889 ] when=20897610612000 04-22 16:10:09.678: I/InputDispatcher

How to use Bitmap font as scene 2d actor?

牧云@^-^@ 提交于 2019-12-05 08:13:49
问题 I am developing a game using libgdx framework. How can i achieve scene2d action on bitmap font object ? so that i can write some text like score,message and run action like scene2d actor. 回答1: Take a look at the Label class, particularly the constructor that takes a CharSequence and a LabelStyle. When you initialize your LabelStyle you can supply a BitmapFont. Please note, if you'd like to scale or rotate the label you'll need to wrap it in a Container or add it to Table with setTransform()

Issue with shaders/matrices - can't see object

落花浮王杯 提交于 2019-12-05 08:09:54
I'm attempting to put a cube on the screen and light it. I'd like a phong shading on the cube. When I run my code, I can see a background image but no cube. I'm fairly sure the cube itself is correct as I've managed to display it with a solid-colour shader. I've managed to get the shader program to compile but I can't see the cube at all. I don't know if GLES/LibGdx have a mechanism for run-time exceptions but I can't see anything in the logs. I'm assuming that The model is out of the field of view The model is being rendered transparent Both I've tried to pare down my code to where I believe

libGDX - Add scores & display it at top left corner of the screen?

倖福魔咒の 提交于 2019-12-05 07:28:31
问题 Here is the sample code of a simple game in libGDX. When a rain drop falls into a bucket,score should be increased by one. And total score should be shown at the top left corner. If 3 drops are missed than display GAME OVER. I know to increase the score but i don't know to display it. Thank you. public class Drop implements ApplicationListener { Texture dropImage; Texture bucketImage; Sound dropSound; Music rainMusic; SpriteBatch batch; OrthographicCamera camera; Rectangle bucket; Array