Android Question libGDX - loading sprite

notedop

Member
Licensed User
Longtime User
Hi,

I'm trying to laod a sprite on a moving background. Background is loaded from a TMX file.
I'm not able to load the png file. Beside that i'm having a hard time with the logic on how to display the plane and update it's position.

Any tips/hints? Note that this is my first attempt with creating games.

regards,
Raoul
 

Attachments

  • test01.zip
    11.5 KB · Views: 146

notedop

Member
Licensed User
Longtime User
I found the error; I rewrote the player class. Next issue was that it was still not loading the file.
I was calling the class in the activity create instead of LG_create...

B4X:
Sub LG_Create

    start.Initialize("naamloos.tmx", Activity.Width, Activity.Height, 0)
   
    'load the airplane texture and create the plane
    plane.Initialize()
   
End Sub

B4X:
Sub LG_Render
    GL.glClearColor(0, 0, 0, 1)
    GL.glClear(GL.GL10_COLOR_BUFFER_BIT)
   
        'Memorizes the time span since the last frame (with a maximum of 50ms, i.e. 20fps)
    DeltaTime = Min(lGdx.Graphics.DeltaTime, 0.05)
   
    LG_Update
   
    plane.plane_draw(DeltaTime)
   
End Sub

B4X:
'Class module
Sub Class_Globals

Private FRAME_COLS As Int = 6
Private FRAME_ROWS As Int = 1

Dim PlaneAnimation As lgAnimation          
Dim PlaneRegion As lgTextureRegion

Dim spriteBatch As lgSpriteBatch
Dim currentFrame As lgTextureRegion

Dim stateTime As Float = 0

Dim X_pos As Int    = 50
Dim Y_pos As Int     = 50

End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize

spriteBatch.Initialize
Dim PlaneSheet As lgTexture    
PlaneSheet.Initialize("actors/plane.png")

PlaneRegion.InitializeWithTexture(PlaneSheet)

Dim tmpWalkFrames(,) As  lgTextureRegion = PlaneRegion.Split(PlaneRegion.Regionwidth/FRAME_COLS, PlaneRegion.RegionHeight/FRAME_ROWS)
Dim WalkFrames() As lgTextureRegion = GetRegionArray(tmpWalkFrames,0)

PlaneAnimation.Initialize(0.1, WalkFrames)

End Sub

Sub GetRegionArray(MultiDimArray As Object, Index As Int) As lgTextureRegion()
    Dim r As Reflector
    r.Target = MultiDimArray
    Return r.GetArray(Array As Int(Index))
End Sub

Sub plane_draw(DeltaTime As Float)

stateTime = stateTime+DeltaTime
currentFrame = PlaneAnimation.GetKeyFrame2(stateTime, True)
spriteBatch.Begin
spriteBatch.DrawRegion(currentFrame, X_pos,Y_pos)
spriteBatch.End

End Sub
 
Upvote 0
Top