Android Tutorial Introduction to the libGDX library

MarcTG

Active Member
Licensed User
Longtime User

Thanks Fred, i did not know that this library existed.This might be a silly question, but can this 3d library be used in libgdx lwp? If not, can we even use it in any lwp in b4a?

Thanks
 

KMatle

Expert
Licensed User
Longtime User
Hi guys,

just started to play with libgdx. Very cool.

Some questions: As I see it, the lib has been adapted for b4a? If yes, what about updates (just to be sure)? Or is it the original lib and the tutorial shows how to implement it in b4a?
 

Informatix

Expert
Licensed User
Longtime User
Some questions: As I see it, the lib has been adapted for b4a? If yes, what about updates (just to be sure)? Or is it the original lib and the tutorial shows how to implement it in b4a?
This lib won't be updated in a near future. I explained why here. Just to give you an idea, there are more than 200 classes and several changes are commited every week in the official library. After a few weeks, there are so many changes that updating the lib takes a full day of work. I let you imagine after a few months. Contrary to what is done in the official project, I try to test every change and rewrite messy or unstable parts, so that needs time and I cannot afford this any longer.
You cannot use directly the original library (as the other libraries for B4A, it needs to be wrapped), and to speak frankly, I trust more my version than the official one.
 

wonder

Expert
Licensed User
Longtime User
Hello Fred,

Once again I need your help....

Imagine I have a game with 100 levels, large textures.

Do I need to load everything at the Create event like this?

B4X:
Sub LG_Create
    'Initializes the renderer
    Batch.Initialize   
   
    For iii = 0 To 99   
        stage_source(iii).Initialize(stage_source_file(iii))
        stage(iii).InitializeWithTexture(stage_source(iii))       
    Next
   
End Sub

or is there another way to load the assets along the game?
 

Informatix

Expert
Licensed User
Longtime User
Everything is possible. You can load all assets at the beginning of the game like a lot of games do (so there will be no loading time during the game) or you can load only the textures that you need, and replace them later by other textures. Maybe loading all textures at the beginning is too long and should be splitted. Only you have the answer.
To load your assets, I strongly recommend to use the Asset Manager.
 

wonder

Expert
Licensed User
Longtime User
Hello again,

I know this might be very simple to implement, but I'm currently having kind of a brain freeze.

This is my "load textures" (short version) code so far:

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim kkkkk As Float
    'GDX
        Dim lGdx As LibGDX
        Dim Gl As lgGL
        Dim Camera As lgOrthographicCamera
        Dim Batch As lgSpriteBatch
       
        Dim stage_source(number_of_stages) As lgTexture
        Dim actor_source(number_of_actors) As lgTexture
       
        Dim stage(number_of_stages) As lgTextureRegion
        Dim actor(number_of_actors) As lgTextureRegion
      
        Dim GLView As View
        Dim Animate = False As Boolean
End Sub


Sub LG_Create
    'Initializes the renderer   
    Batch.Initialize
    Set_First_Cycle
       
    For iii = 0 To (number_of_actors - 1)   
        actor_source(iii).Initialize(sprite_source(iii))
        actor(iii).InitializeWithTexture(actor_source(iii))        
    Next
End Sub


Sub Setup_Ryu   
    active_actor = Ryu
    actor_unique_ID(active_actor) = "RYU"
   
    actor_type(active_actor) = "PLAYER"
   
    sprite_source(active_actor) = "image1.png"
End Sub

What would be the best way to implement various "pages" of textures, where for example the frames for Punch Animation are located on the 1st page (image1.png) and the frames for the Jump Animation are located on the 2nd page (image2.png)?
 

Informatix

Expert
Licensed User
Longtime User
Create a texture atlas.
 

Brizky

Member
Licensed User
Longtime User
What's up, folks.

I work with VB.NET on a daily basis, I'm relatively new to Basic4Android but it doesn't look like it'll be an issue. But I am new to programming games. I read through the intro to LibGDX and then briefly ran through the Developer Guide located at https://github.com/libgdx/libgdx/wiki .

The only problem I seem to be having is locating something like a CLASS REFERENCE guide for ligGDX. Reading through the intro I was often thinking "what does this parameter in the function do?" or "why use this function?". And the developer guide goes over some code via its examples but seems to explain some things as if you already know what you're doing.

Like I said, I'm completely new to programming games. So I'm looking for some kind of document that says "These are all the objects", "this is what each object is used for", "these are the methods for these objects", "these are the parameters for these methods, functions, subs and here's what each parameter does".

Is there any kind of document like that out there?
 

Informatix

Expert
Licensed User
Longtime User
You can browse the complete list of classes and functions with this tool: B4x Object Browser
or you can read the Java documentation here: http://libgdx.badlogicgames.com/nightlies/docs/api/
To learn the basics of programming a game, you should look at my tutorial on this matter.
 

Brizky

Member
Licensed User
Longtime User

Sia

Member
Licensed User
Longtime User
Hi,
how can give me sample of drawing a surface.
fist of all i tried draw it with canvas and drawline and then tried to draw surface with Body3D and now @Informatix tell me it's better to use libgdx and i think it's better
but i can't find any sample in internet
i tried to draw very easy sample mesh but i can't
i find lgMesh in this library but i can't find any solution for drawing x,y,z
please give me sample of drawing a surface.

very thanks.
 

Malky

Active Member
Licensed User
Longtime User
Hi informatix, (correct thread this time).

I am just trying a few tests to make sure I have a handle on this, but I'm getting a java error:-
com.badlogic.gdx.utils.GdxRuntimeException: Texture width and height must be powers of two: 398x500

B4X:
Sub LG_Create
    'Sets the InputProcessor
    IP.Initialize("IP")
    ScreenW = lGdx.Graphics.Width
    ScreenH = lGdx.Graphics.Height
    Batch.Initialize
    myBacking.InitializeWithFile(lGdx.Files.internal("day_background.png"))
    '...
End Sub

Trying to initialize the myBacking image is the problem?
It seems any image I try to load gives the same error (obviously with the different files sizes). Am I missing something obvious?

Malk
 

Informatix

Expert
Licensed User
Longtime User
What's the version of your libGDX library ?
 

Malky

Active Member
Licensed User
Longtime User
You should update it.
Will do, thanks for that. I haven't been using b4a since last May with work and maintenance stuff, so trying to get back into it. Never even knew it had been updated. Thanks you very much for your prompt replies.

Malk
 

Malky

Active Member
Licensed User
Longtime User
Hi again Informatix, sorry to bother you again. Has anything else changed in the new version I am unaware of?

I now get this error:-
java.lng.NullPointer Exception
at com.badlogic.gdx.graphics.g2d.SpriteBatch.flush(SourceFile:958)
with this line of code
Batch.DrawTex2(pandaFrontTexture,mypanda.x,mypanda.y,ScreenW*0.08,ScreenH*0.2)

I had all this working before I thought about trying the gestures instead of buttons.

EDIT: Meant to say this line is in the LG_Render function!
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…