Android Question [SOLVED] LibGDX - Actors Not Rendering

Discussion in 'Android Questions' started by Jeffrey Cameron, Mar 30, 2015.

  1. Jeffrey Cameron

    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:
    ' Do main stage
    If Main.OkToRenderFlag = True Then
    "** ERROR clsGame.Render: Main.MainStage.Draw: " & LastException.Message, Colors.Red)
    End Try 
    End If

    ' update other things

    ' Do the map stage
     If Main.OkToRenderFlag = True Then 
    ' clip map and its actors to the group window on main stage
    ' render map
    ' draw actors
    ' stop clipping
    "** ERROR clsGame.Render: Main.MapStage.Draw: " & LastException.Message, 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?
  2. walterf25

    walterf25 Well-Known Member Licensed User

    How are you adding your actors to the stage?
  3. Jeffrey Cameron

    Jeffrey Cameron Well-Known Member 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.

    Last edited: Mar 30, 2015
  4. walterf25

    walterf25 Well-Known Member Licensed User

    Have you added this to your project?
    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
  5. Jeffrey Cameron

    Jeffrey Cameron Well-Known Member Licensed User

    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: Mar 30, 2015
  6. Jeffrey Cameron

    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:
    '  Load a random map
    '  Init the renderer
     MapRenderer.Initialize2(TiledMap, MapStage.SpriteBatch)
    ' now just dispose it
    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.


    Thank you, Walter, for your suggestions!
    DonManfred likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice