scene2d

How to restart screen in LibGDX using Init() methods?

夙愿已清 提交于 2019-12-20 07:15:55
问题 I created a simple game in LibGDX that has multiple screens. I want to restart a certain screen after touching a restart button but I'm not sure how to do that. I made some research about this and all answers lead to not loading my assets in show() but rather in an init() method that I am not really familiar with. I want to know how can I restart a screen using this init() method . As of now I put most of my initialization in the constructor and some were initialized in methods such as the

Putting Freetypefont into libgdx skin

大憨熊 提交于 2019-12-18 14:48:21
问题 In my uiskin.json I have this com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: text/default.fnt } } This is fine for when I have the default.fnt in my text folder in the assets folder... However I want to use a Freetypefont. How do I create a Freetypefont and load it into the uiskin file? 回答1: It is not possible to do it beforehand, since you are going to generate it at runtime. My workaround would be to keep the default font as it is and replace it at runtime via code. You

Using scene2d.ui with libgdx: where does the skin come from?

我与影子孤独终老i 提交于 2019-12-17 12:36:10
问题 I've read about libgdx's scene2d features, including the UI elements, but I can't get them to work. They all seem to use a skin object, how do I create one? I've gone through the nice tutorial that creates a simple libgdx game catching raindrops in a bucket, and I've created a simple board game app by loading images with a texture atlas. However, scene2d sounds like a better way to control the moving pieces in a board game app, as well as any buttons and menus. 回答1: To load a skin, you can

How is it possible to pause an action of an actor in LibGDX?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 05:03:59
问题 I added the following action to my actor: this.addAction(sequence(delay(0.5f), alpha(1, 2), delay(2), alpha(0, 2))); Is there an easy way to pause this animation and then continue it when a button is clicked? 回答1: If your actor is only running action, I suggest to stop calling the act() method of the actor. Extend Actor to set a switch if needed. public void act(){ if(mUpdateAnimation){ this.act(delta) } } 回答2: Although the above answer is accepted, but when I tried the above solution, the

LibGDX Nesting Tables for gameboard grid

天涯浪子 提交于 2019-12-12 01:19:10
问题 I am playing with LibGDX and trying to set up a simple board game. public void show() { width = Gdx.graphics.getWidth(); height = Gdx.graphics.getHeight(); viewport = new FitViewport(STAGE_WIDTH, STAGE_HEIGHT); stage = new Stage(viewport); sceneBoard = new GridSceneBoard(10, 30, GridBoardCell.Type.CHECKERED); rootTable = new Table(); rootTable.setFillParent(true); sceneBoard.setFillParent(true); rootTable.add(sceneBoard); stage.addActor(rootTable); Gdx.input.setInputProcessor(stage); } a

LibGDX persist actors while switching screens?

一世执手 提交于 2019-12-11 19:04:04
问题 I'm making a game in LibGDX and I have a couple of menu screens using the scene2d ui. I have one MenuBaseScreen super class that sets up the default actors required for each screen. Then i have a MainMenu, Options etc screens that each inherit from MenuBaseScreen. In each of the screens there is a parallax background that keeps going from right to left. This parallax background gets instantiated in the MenuBaseScreen. Now the problem with this is that each time I switch screen there is a

How to make a box2d Body object collidable with the other Body

不想你离开。 提交于 2019-12-11 16:17:18
问题 How to make a com.badlogic.gdx.physics.box2d.Body object collidable with the other Body in Scene2d(libgdx) while working with the Box2d extension, when both the body types are Dynamic.? 回答1: if I understand correctly, your question can this helps where to create the Body2, add this example in your code: .// YourBody2 = YourWorld.createBody(bd); YourBody2.createFixture(fixDef).setUserData("YourBody2"); where to create the Body1, add this example in your code: .// YourBody1 = YourWorld

Is it possible in LibGDX's `scene2d` API to have the same Actor instance in multiple Stages?

本小妞迷上赌 提交于 2019-12-11 05:30:02
问题 I am making a program using the amazing libGDX +scene2d API and I structured it as follows: I have a single MyGame instance, holding a single PolygonSpriteBatch instance. There is an abstract MyScreen class, holding a MyStage class (see below) Then there are lots of different screen classes that inherit from MyScreen , and instantiate each other at will. (in all cases, removing the " My " gives you the name of the respective library class that it extends) This model worked fine, until I

How to get the world coordinates of a point in a child actor?

三世轮回 提交于 2019-12-10 07:01:03
问题 I have Group objects that consist of other Group objects, that finally consist of Actor objects. Now, when the groups and actors are rotated, offset and scaled, the coordinates in the "world", or in relation to the root node change. How do I get the world coordinates of a point in an actor's local space? To illustrate a bit more, here's an example of what I want: Group parentGroup; Actor childInGroup; ... parentGroup.addActor(childInGroup); childInGroup.setPosition(10f, 15f); childInGroup

overriding drawing order scene2D's stage

耗尽温柔 提交于 2019-12-09 16:06:27
问题 You are given a complex Scene2D graph in libgdx with several Group's and Actor's . You want the user to select some Actors and draw those at the end so they appear focussed on top of any other Actors . I would like to iterate over the Stage twice. The first time it draws the unselected Actors , the second time it draws the selected actors . I don't see any 'good' way to enforce this behaviour however. I would prefer options that are clean. I would not like to copy an entire method