Android Tutorial Introduction to the libGDX library

boten

Active Member
Licensed User
Longtime User
I understand that
B4X:
lGdx_GL.glClearColor(0, 0, 1, 1) 'Blue background
lGdx_GL.glClear(lGdx_GL.GL10_COLOR_BUFFER_BIT)
will clear the the screen with Blue.

I want to create a transparent "surface" so that the Activity's background will show (perhaps showing the REAL world thru the camera)
I tried adjusting the 4th parameter (alpha?) to get a transparent background, but even setting to 0 did not work.

In essence, is there a way that the "background" of libgdx will show the REAL world thru the device camera?
 

Informatix

Expert
Licensed User
Longtime User
To achieve this, you have to set the format of the holder of the surface view to PixelFormat.TRANSLUCENT. Impossible to do with the current functions and properties, and a bit cumbersome to do with the reflection library. It's a lot better to paint your camera view in the libGDX surface, if possible (I never used the camera libs available for B4A so don't ask me how to do it).
Note that using transparency involves a blending between the foreground and the background which is a bit expensive. Avoiding transparency on whole screen is recommended.
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi,

I have created a label and successfully displayed it on my screen. I wanted to rotate it and Informatix suggested to use the rotateBy property

I have tried it but without success...

B4X:
    lblScore.x  = vpW/3
    lblScore.Y = vpH/2
    lblScore.Rotation=90.0
    lblScore.rotateBy(90.0)
    lblScore.Draw(Batch,1)

Everything is fine, compil is ok but the text is displayed but definitively not rotated. Any combination of Rotation or rotateBy doesn't change anything.

Where is my mistake ?
thanks
 

Informatix

Expert
Licensed User
Longtime User
Draw your Scene2D widgets with Stage.Draw (cf. lgScn2DStage) or use the Spritebatch object created by the stage class.
For group widgets, you will have to set Transform to True to draw children with the specified rotation and scaling values.
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Draw your Scene2D widgets with Stage.Draw (cf. lgScn2DStage) or use the Spritebatch object created by the stage class.
For group widgets, you will have to set Transform to True to draw children with the specified rotation and scaling values.
Thank you Informatix.

All this is not totally clear for me... I will try to understand the stage and sprite concepts... any link for a noobs documentation ?
 

freedom2000

Well-Known Member
Licensed User
Longtime User
The libGDX tutorial, as usual. And if you want to know more, you should read the official wiki.
Thanks afgain !

I have found the Scene2D paragraph including stage/actors/widgets/tables

As far I understand, my poor label is a widget :
  • lgScn2DLabel displays a text using a bitmap font and a color. The text may contain newlines (CRLF).


I have created a stage and added my label
B4X:
    stage.Initialize("ST")
    stage.AddActor(lblScore)

Then tried to draw it in the render event

B4X:
    lblScore.x  = vpW/3
    lblScore.Y = vpH/2
    lblScore.Rotation=90.0
    lblScore.rotateBy(90.0)
    'lblScore.Draw(Batch,1)
    stage.Draw

but nothing is displayed...

Lost in stage
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Look at the many examples provided.
Yes it's what I am currently doing ...
I have found Cloney BIrd which does not use stages and actors
and your excellent PacDroid... but which is quite advanced for me ...
 

freedom2000

Well-Known Member
Licensed User
Longtime User
I meant the examples provided with the library. All those starting with Scene2D_.
And note that the tutorial explains how to declare and use an actor. So reading it is probably useful.
Ok thanks I will go and see these tutorials
 
Last edited:

freedom2000

Well-Known Member
Licensed User
Longtime User
I meant the examples provided with the library. All those starting with Scene2D_.
And note that the tutorial explains how to declare and use an actor. So reading it is probably useful.



I tried the codes scene2D and specially scene2D_Table

I have tweaked the code to rotate an image

B4X:
    'Creates a few cells with text and images
    Table.AddLabel2("Stars:", Font, Font.Color.ORANGE).AlignRight

    For i = 1 To 4
        Dim Star As lgScn2DImage
        Star.InitializeWithDrawable(Atlas.CreateRegionDrawable("particle-star"), "")
        'Star.rotateBy(90)
        'star.Rotation = 90
        Table.AddActor(Star)
    Next

Both methods work fine for images : the Stars rotate

But they don't for a label (or at least I don't know how...)

The label added with Table.AddLabel2(...) doesn't have a rotate method...
I have tried to add a lgScn2DLabel ... but didn't succeed either

I have spent hours on this... I give up
 

Informatix

Expert
Licensed User
Longtime User
I usually use tables for everything in libGDX so I didn't even notice that labels cannot rotate alone. Thanks for pointing this out. I will try to provide a solution in the next version. For now, use tables (or any other group widget). And sorry for the time lost.

Adding these two lines after line #143 in Scene2D_Table will rotate all table images and labels:
Table.Rotation = 20
Table.Transform = True
 

freedom2000

Well-Known Member
Licensed User
Longtime User

Time is never lost --> I have learned a lot

Thank you for the trick to rotate a table.
 

Informatix

Expert
Licensed User
Longtime User
From the official wiki:
 

Toley

Active Member
Licensed User
Longtime User
Hello Frédéric,

I have try to run the particle editor and I got this error message. I know this is not your tool but maybe you have an idea. Thank you very much for these tutorials. I'm just at the beginning and have a lot to learn but I really enjoy it.

 

Informatix

Expert
Licensed User
Longtime User
Je viens d'essayer avec le dernier nightly build (libgdx-nightly-20140520.zip) et ça fonctionne parfaitement.

I just tried with the latest nightly build (libgdx-nightly-20140520.zip) and that works fine.
 

persianpowerman1

Active Member
Licensed User
Longtime User
how may i debug...?
You cannot use the debugger of B4A with libGDX because most of the code of the library runs in a different thread. You have to use the Log function to debug your game.

basically for a better understanding i wana see what is happening at every step of the deltatime gap...? how may i do that.. possible?

YO!han
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…