Android Tutorial Introduction to the libGDX library

Informatix

Expert
Licensed User
Longtime User
libGDX almost never uses double values, only float values. If you limit your computations to two or three decimal places after the dot, Float is enough and saves a bit of memory. And since the pixels cannot be divided, you should use only integers with your method; you place the first tile at (intX, intY), then you place other tiles at (intX+intOffsetX, intY+intOffsetY). This is how proceeds the OrthogonalTiledMapRenderer class.
 

wonder

Expert
Licensed User
Longtime User
You're right about doubles being overkill when LibGDX uses only floats... It's just an old habit of mine to favor Doubles over Floats.

Nonetheless, I do experience difference behaviour (movement) when switching between Ints and Doubles/Floats. At first, it made no sense to me as well. After all, there is indeed no such thing as a half-pixel.

Soon, however, I came to realize that Photoshop, for example, does allow you to place guides at pixel locations with decimal places. Googling around, my curiosity took me to this webpage, which has it demonstrated pretty well (at least for CSS): http://atirip.com/2013/09/22/yes-we-can-do-fraction-of-a-pixel/

So long story short, (EDIT: If your game has a lot of movement) I think it's okay (and I even recommend) to use pixel values with decimal places (Float).
I can make a comprasion video of Ints vs Floats, if necessary.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
I considered that your camera unit was the pixel. It could be something very different (especially if you use Box2D) and my advice would be stupid indeed. However I think that you misunderstood me. I suggested to use integers only when you draw your tiles, not everywhere. In my apps, I use floats also to store X and Y, and to do all computations. You could get very inaccurate results if you used only integers (e.g. when you scale something).
Anyway, if you use another unit than the pixel for your camera, you can forget my advice.
 

wonder

Expert
Licensed User
Longtime User
True, I might have misunderstood you, I was thinking about a "tile" being something like a moving spaceship...
Well, as long as it "feels great, looks good and plays well", there's no need to overthink subject too much.
 

ilan

Expert
Licensed User
Longtime User
hi,

i need a little bit help and i really searched before in the forum and also tried all libgdx examples but i could not figure out how to solve my problem

i am looking for a view that i can handle touch down and touch up.
the lgScn2DButton only recognize a click but what i need is a view that on touch an action will perform and on release that action will stop like a Gas Pedal in a racing game.

and also if i exit that view the touch up should fire like if i touch it down and then hold down and move my finger out of the screen while it is touching the screen then the touch up should be fired. is there such a view in libgdx?

thanx, ilan
 

Informatix

Expert
Licensed User
Longtime User
Add an lgScn2DInputListener (or a lgScn2DGestureListener) to your view so you can handle the TouchDown/TouchUp events.
This is explained at the beginning of this thread in the Scene2D chapters.
 

ilan

Expert
Licensed User
Longtime User
Add an lgScn2DInputListener (or a lgScn2DGestureListener) to your view so you can handle the TouchDown/TouchUp events.

thank you informatix so i could use an lgScn2DImage and add to it an lgScn2DInputListener?
hmm why i have not think of it?
 

ilan

Expert
Licensed User
Longtime User
another question please, to make a level selcetion menu should i add all Actors (lgScn2DImage or lgScn2DButton) to a Stage and like this i could animate the whole stage with interpolation?
 

Informatix

Expert
Licensed User
Longtime User
another question please, to make a level selcetion menu should i add all Actors (lgScn2DImage or lgScn2DButton) to a Stage and like this i could animate the whole stage with interpolation?
I'm not sure to understand the question. First because all actors are always added to a stage (or they are useless) and second because you can animate any group of actors, not only the stage.
 

ilan

Expert
Licensed User
Longtime User
ok i have managed to add a stage with an actor to it and add a inputlistner to the actor.

what i have noticed is that the lgInputProcessor events will still fire if i touch the actor.
so i get now 2 logs (1 touch down from the lginputprocessor and 1 from the inputlistner of the actor)
is there a way to avoid the lginputprocessor to fire when i touch the actor?


another thing i noticed is that if i touchdown the actor and slide my finger out of it the touchup will not fire until i stop touching the screen even i am out of the actor bounds.
is there a way to get the touch up event fire when i am out of the actor bounds?

thanks a lot, ilan

EDIT: ok i solved issue nr. 1, it depends what you intialize first. if you intialize the inputlistner then the lginputprocessor will not fire.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
There's no reason to trigger a TouchUp while the finger is still down (or the event has a meaningless name). If you want to know if the finger is out of the actor bounds, use the Exit event.
 

ilan

Expert
Licensed User
Longtime User
hi, (again a small question )

i am working on a box2d + libgdx game.
i am using several lgScn2DStage in my game but the problem is that the last stage is blocking other stage actor getting touch events.

so the stage that is intialized last will get all touch. how can i disable a stage so i can move another stage and click on his Actors?


EDIT: i tried gamestage0.UnfocusAll but i still cannot touch on actors in other stage.
 

Informatix

Expert
Licensed User
Longtime User
If you have more than one stage per screen, there's something wrong in your design. The stage is like an activity. Would you create many activities for the same screen in a standard app?
 

ilan

Expert
Licensed User
Longtime User
If you have more than one stage per screen, there's something wrong in your design. The stage is like an activity. Would you create many activities for the same screen in a standard app?

but i need more then 1 stage.
1 stage is for the buttons and they are static but another stage is the same size like my world (box2d) and i add actors to it so i can add interpolation to them (coins flying).
and it is working fine. now i wanted to add another stage as the menu but if it is not possible i will use the same stage as for the controls (that are static) also for the menu and draw everything on the right time (ingame = true or inmenu = true)

can i add interpolation to a box2d body?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Be aware that the library is not designed for more than one stage per screen, so you will probably face troubles. I cannot guarantee that the event system will work reliably in such a context.
I'm sorry but I can't see the reason to have a stage for the buttons, a stage for the menu, a stage for the Box2D world, etc. Why don't you use the same stage for everything? The distinction between static and dynamic actors is absolutely not relevant. I could understand that you want to support different coordinate systems, with multiple cameras and viewports, but that sounds a bit complicated to manage and simplicity is probably better.
I made three "complex" games, with two of them having heavily loaded stages, and I did not see any reason to have more than one stage, so you're in an uncharted territory for me.
 

ilan

Expert
Licensed User
Longtime User
thank you a lot fred for your explanation. i thought i could use a stage like a panel but u r right i will redesign my game.
i will use only 1 stage and for the coin flying effect i will just apply a force or set the Linear Velocity of the body instead of using interpolation on an actor.

2 small question please.

1. can i group lgscnactors together? and move them around or do i have to do it for each actor?
2. hiding the actor will prevent calling the listener touch event when clicking on that area (like a normal android button)?

thank you, your help is very much appreciated
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…