Android Question [SOLVED] LibGDX - Actors Not Rendering

Jeffrey Cameron

Well-Known Member
Licensed User
Ok, after getting my tiledmap to render within the bounds of a group, the actors are not rendering on the stage.

I added a log statement into the actor's draw event, so I am positive the event is firing and that the actor x/y is at the correct position on the stage, so I'm a little puzzled as to why nothing is being drawn.

The render event code is pretty basic:
B4X:
' Do main stage
 Main.MainStage.Camera.Update  
 If Main.OkToRenderFlag = True Then
     Try
         Main.MainStage.Act
         Main.MainStage.Draw
     Catch
         modMain.MyLogColor("** ERROR clsGame.Render: Main.MainStage.Draw: " & LastException.Message, Colors.Red)
         Return 
     End Try 
 End If

 ' update other things
 Update

 ' Do the map stage
 If Main.OkToRenderFlag = True Then 
     Try 
         Main.MapStage.Camera.Update  
         Main.MapStage.Act 
         ' clip map and its actors to the group window on main stage
         moMapGroup.ClipBegin 
         ' render map
         Main.MapRenderer.SetCameraView(Main.MapStage.Camera)
         Main.MapRenderer.Render 
         ' draw actors
          Main.MapStage.Draw 
         ' stop clipping
          moMapGroup.ClipEnd
     Catch
         modMain.MyLogColor("** ERROR clsGame.Render: Main.MapStage.Draw: " & LastException.Message, Colors.Red)
Colors.Red)
     End Try 
 End If
Everything else renders fine, the main stage and its widgets, the map and all its layers (which you can pan/zoom just fine) just not the actors (which, I have double-checked are added to the MapStage, not the MainStage).

I've not used the Clip commands before; is there some step or command I need to issue prior to issuing the Draw method to make the stage's actors render?
 

walterf25

Expert
Licensed User
Ok, after getting my tiledmap to render within the bounds of a group, the actors are not rendering on the stage.

I added a log statement into the actor's draw event, so I am positive the event is firing and that the actor x/y is at the correct position on the stage, so I'm a little puzzled as to why nothing is being drawn.

The render event code is pretty basic:
B4X:
' Do main stage
Main.MainStage.Camera.Update 
If Main.OkToRenderFlag = True Then
     Try
         Main.MainStage.Act
         Main.MainStage.Draw
     Catch
         modMain.MyLogColor("** ERROR clsGame.Render: Main.MainStage.Draw: " & LastException.Message, Colors.Red)
         Return
     End Try
End If

' update other things
Update

' Do the map stage
If Main.OkToRenderFlag = True Then
     Try
         Main.MapStage.Camera.Update 
         Main.MapStage.Act
         ' clip map and its actors to the group window on main stage
         moMapGroup.ClipBegin
         ' render map
         Main.MapRenderer.SetCameraView(Main.MapStage.Camera)
         Main.MapRenderer.Render
         ' draw actors
          Main.MapStage.Draw
         ' stop clipping
          moMapGroup.ClipEnd
     Catch
         modMain.MyLogColor("** ERROR clsGame.Render: Main.MapStage.Draw: " & LastException.Message, Colors.Red)
Colors.Red)
     End Try
End If
Everything else renders fine, the main stage and its widgets, the map and all its layers (which you can pan/zoom just fine) just not the actors (which, I have double-checked are added to the MapStage, not the MainStage).

I've not used the Clip commands before; is there some step or command I need to issue prior to issuing the Draw method to make the stage's actors render?
How are you adding your actors to the stage?
 

Jeffrey Cameron

Well-Known Member
Licensed User
How are you adding your actors to the stage?
I have a class that encapsulates the actors, once an actor class is initialized, I issue Main.MapStage.addActor(actorclass.Actor).

I have noticed one oddity... The game currently supports both portrait and landscape but has no state-saving code yet. The net effect being when you change orientation it re-loads everything and restarts. When you initially start the game in either orientation no actors are rendered. But once you change orientation, and the game reloads, the actors WILL appear from that point forward, regardless of the orientation.

Addendum -
Ok, this is even stranger. When I run the app from the B4A IDE in release mode, it behaves as I described above. If I launch the app from the device's menu directly it renders the actors properly the first time, every time.

Suggestions?
 
Last edited:

walterf25

Expert
Licensed User
I have a class that encapsulates the actors, once an actor class is initialized, I issue Main.MapStage.addActor(actorclass.Actor).

I have noticed one oddity... The game currently supports both portrait and landscape but has no state-saving code yet. The net effect being when you change orientation it re-loads everything and restarts. When you initially start the game in either orientation no actors are rendered. But once you change orientation, and the game reloads, the actors WILL appear from that point forward, regardless of the orientation.

Addendum -
Ok, this is even stranger. When I run the app from the B4A IDE in release mode, it behaves as I described above. If I launch the app from the device's menu directly it renders the actors properly the first time, every time.

Suggestions?
Have you added this to your project?
B4X:
Sub Activity_Resume
    'Informs libGDX of Resume events
    If lGdx.IsInitialized Then lGdx.Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    'Informs libGDX of Pause events
    If lGdx.IsInitialized Then lGdx.Pause
End Sub
 

Jeffrey Cameron

Well-Known Member
Licensed User
Have you added this to your project?
Yes, the Main activity handles the lib creation/pause/resume/dispose. Each "screen" is its own class module and the screen manager sinks all the show/hide/etc. events to the appropriate class.

As I noted in my addendum, if I run the app from the IDE no actors are rendered, but if I run the app from the device menu (the log still shows up in the IDE) the actors are rendered. All of the same log statements are displayed each time, all with the same values.

This is what is confusing me.

Edit -
It seems the first time I run it, from the IDE or from the device menu, no actors are rendered. If I then close the app and run it again (or change orientation) then the actors will appear from that point forward until the device is reset (or the app is reinstalled).
 
Last edited:

Jeffrey Cameron

Well-Known Member
Licensed User
For what it's worth, I've solved my own problem. I still have no explanation as to why I have to do this, but the net effect is the actors are rendered on the first run of the app.

What I did was, in my Main activity base LibGDX render thread; after the asset manager load has completed and after everything else has been initialized:
B4X:
'  Load a random map
 LoadRoundMap(1)
'  Init the renderer
 MapRenderer.Initialize2(TiledMap, MapStage.SpriteBatch)
 ' now just dispose it
 MapRenderer.dispose
Then everything proceeds as it did before from there. Once the player options have been selected, the correct map is loaded and initialized in the same spot it always was but this time all the actors show up on the map.

/boggle

Thank you, Walter, for your suggestions!
 
Top