Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 1415 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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
    Table playerInfo = new Table();
        //playerInfo.top().left();
        playerInfo.defaults().space(3f);
        playerInfo.pad(10f, 10f, 0, 0);
        playerInfo.debug();
        playerInfo.setPosition(0, Gdx.graphics.getHeight());
        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 :
1  
2  
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:
1  
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:
1  
2  
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:
1  
2  
3  
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:
1  
2  
3  
4  
5  
6  
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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (31 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!