Android Question how to view atlas file in libgdx ?

Addo

Well-Known Member
Licensed User
Longtime User
i have this atlas file that i want to show in my android app

i searched in form and i found libgdx library any idea how to load an atlas file into it ?
 

Attachments

  • ferrari.zip
    77.8 KB · Views: 186
Solution
the project i test on is a simple new project it always raise error whenever i try to initialize the atlas File

your code will not do much. using libgdx is not simple you need to do much more than just initialize an atlas object.
i wrote a long time ago for my own needs a simple class to load images from an atlas file for a b4i game and then i published it here for free in my breakout game i did.

anyway, i did a simple animation for the Ferrari. i would recommend you to name the images with names that make sense and not call the Ferrari = "che_13"

i also included the atlas class in this example.
what i do in this code is just putting the Ferrari bitmap to an image view and moving the image view. this is something that i...

Addo

Well-Known Member
Licensed User
Longtime User
i have tried

B4X:
Dim atlas As lgTextureAtlas


Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    
    atlas.InitializeWithFile("ferrari/ferrari.atlas")
End Sub


i got this error

main_activity_create (java line: 352)
java.lang.NullPointerException: Attempt to invoke virtual method 'com.badlogic.gdx.files.FileHandle com.badlogic.gdx.backends.android.AndroidFiles.internal(java.lang.String)' on a null object reference
at anywheresoftware.b4a.libgdx.graphics.lgTextureAtlas.InitializeWithFile(SourceFile:44)
at b4a.example.main._activity_create(main.java:352)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at b4a.example.main.afterFirstLayout(main.java:105)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:900)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:219)
at android.app.ActivityThread.main(ActivityThread.java:8387)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
are you making a game with libgdx or do you want to use an Atlas file for another purpose?

are u running your app in debug mode? Note that when you use Libgdx you can run it only in Release Mode!
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
the project i test on is a simple new project it always raise error whenever i try to initialize the atlas File

your code will not do much. using libgdx is not simple you need to do much more than just initialize an atlas object.
i wrote a long time ago for my own needs a simple class to load images from an atlas file for a b4i game and then i published it here for free in my breakout game i did.

anyway, i did a simple animation for the Ferrari. i would recommend you to name the images with names that make sense and not call the Ferrari = "che_13"

i also included the atlas class in this example.
what i do in this code is just putting the Ferrari bitmap to an image view and moving the image view. this is something that i would never do but i wanted to make it simple for you. i would use canvas to draw the sprite on it or any other game framework but i don't know what is your goal with this animation so i made it very simple.

code included, have fun!

 

Attachments

  • animate.zip
    81.5 KB · Views: 196
Upvote 1
Solution

ilan

Expert
Licensed User
Longtime User
Note that you can also animate views with imageview1.SetLayoutAnimated command but it will do a single animation. for a repetitive animation use a timer.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
The code i posted were just raise an error not found i know that i should do more after initialized but the main issue is i couldn't initialized the atlas file always raising an error

in the libgdx examples you can see how @Informatix is loading images from an atlas file. you may have a look on them.
i have not investigated your issue to much because i find it a waste using such a huge library for simple tasks you want to do.

anyway if you still want to use libgdx check the libgdx examples and also something important don't add folders inside the file.dirassets folder. put all files in the dirassets folders without directories!
 
Upvote 0
Top