Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (688)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  libGdx HUD/ UI + PathFinding  (Read 2201 times)
0 Members and 1 Guest are viewing this topic.
Offline theOne

Senior Newbie

« Posted 2013-09-02 20:45:13 »

Hello, I would like to know how it is possible to make an Interface in libgdx? I knew the Channel from dermetfan and some Tutorials, but I donĀ“t get it to 100%.

Is it possible to set a screen ontop of another Screen or do I have to use Stage for the UI?

Lets say I want to make an hp/mp bar what would I have todo to draw this? Currently I am doing it just like this
    Table playerInfo = new Table();
        playerInfo.pad(10f, 10f, 0, 0);
        playerInfo.size(200f, -100f);
        playerInfo.add(new Label("HP: ", skin)).size(25f, 20f);
        playerInfo.add(new Label("", skin)).size(75f, 20f).row();
        playerInfo.add(new Label("MP: ", skin)).size(25f, 20f);
        playerInfo.add(new Label("", skin)).size(75f, 20f).row();

In order to use an normal Image like in every common Game how todo? Especially I dont get how to draw the pixel, when the bar is not full. So, would it be correct to draw the bar surronding and load it then per LabelStyle? So the Background? Or just an different Class? How then i draw the red pixels according to the health?

How do i do it that it looks like an Window? ....Ah I can make an Window Class and then add to it an Table, great.
How can I make the positions better? When u look at the above example, its very annoying with the fixed sizes, is there somekind of Layout possible?

Well for Pathfinding Algorithms I need the Map data, so should i read everytime from the Tiledmap from libgdx or make an own Map Class and then fill it with an 2d Array just if the Tile is blocked or free?
Offline ReBirth
« Reply #1 - Posted 2013-09-03 02:59:46 »

Use Image class. It extends Widget so it can be added to Table. Use full bar image, then adjust the scaleX value according to player's HP.

Offline theOne

Senior Newbie

« Reply #2 - Posted 2013-09-05 18:04:28 »

Thanks, but i still dont get it.

So, i should make an Image with the full HP/MP and instantiiate it as an Image, okay.
But how then i set the pixxels inside the Bar? The only thing i can think about is taking something like a Progressbar, but yeah that wouldnt be very handy...

And is there maybe an easy way to get to the informations of an TiledMap?
Only to get to the Tilesize I do :
TiledMapTileLayer layer= (TiledMapTileLayer)gameMap.getLayers().get(0);
       return layer.getTileWidth();

Especially; If there is an way how to get the Tile I am standing or clicking? Currently I am just divididing the position tru the Tile Size, but its not very sophisticated...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2013-09-06 03:08:32 »

Progress bar is handy. You don't set pixel, you scale it.

Offline dermetfan
« Reply #4 - Posted 2013-09-06 14:28:20 »

You can get the tile size easier like this:
float tileWidth = map.getProperties().get("tilewidth"); // or tileheight

The TmxMapLoader or something automatically puts the property there.

The table often sizes its children automatically. If you want them to have specific dimensions, there's no way around setting them hard-coded or calculating them yourself.

For a health bar, I'd recommend a Slider (doc). It let's you choose your own scale for example from 5 to 10 or in percent or any other way you want.

Check out the A* algorithm for pathfinding (MAYbe there will be a video about it). To be able to use it, you have to create a grid with custom nodes/tiles anyways, so just create one when the map is loaded.

By the way, you can create the labels quicker if you pass the Skin in the Tables constructor:
Table table = new Table(skin);
table.add("this is gonna be a label with default style from the skin");

Offline theOne

Senior Newbie

« Reply #5 - Posted 2013-09-06 17:46:25 »

Ahh slider, right.
But how to add there the "HP"? So draw the background/borders and then how do i fill it? I see that there is an setter for that, but how to draw em? Maybe something with the draw() and then make the batch red?
BTW, is there an Bug? If I set disabled true, I am still able to change the value.

Yeah the Algorithms is not the Problem, more libgdx.
It makes Cells into TiledMapLayers and TiledTiles into Cells and Layers int MapLayers. So, what should I take to create an easy Map for the Pathfinder? It also seems taht the TileLayers dont have the same size as the created Map, at least if the TileLayer is not so big as the map.
So, from which class can i get the stuff?

Yeah i hardcoded some sizes, but they didnt aplly. Either on the texture or on the Widget.
Offline dermetfan
« Reply #6 - Posted 2013-09-07 12:33:52 »

Here's a little test I wrote for the Slider. The relevant part of my skin file:
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
   default-horizontal: { background: default.background, knobBefore: default.selection }

It worked all fine for me, so I guess there is no bug.

You could create  a boolean or float array, depending on the type of your algorithm (with weighting or not) of the size of the tile map.
For example:
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayer("pathfinding");
float width = map.getProperties().get("width"), height = map.getProperties().get("height");
float[][] pathfindingMap = new float[width][height];
for(int x = 0; x < pathfindingMap.length; x++)
    for(int y = 0; y < pathfindingMap[x].length; y++)
        pathfindingMap[x][y] = layer.getCell(x, y).getTile().getProperties().get("weight", Float.class);

Then do the pathfinding using the pathfindingMap. Didn't test though.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (74 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (79 views)
2015-10-31 01:32:37

williamwoles (107 views)
2015-10-23 10:42:59

williamwoles (93 views)
2015-10-23 10:42:45

Jervac_ (112 views)
2015-10-18 23:29:12

DarkCart (137 views)
2015-10-16 00:58:11

KaiHH (118 views)
2015-10-11 14:10:14

KaiHH (158 views)
2015-10-11 13:26:18

BurntPizza (173 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!