• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

[mojo2][android] How to load images asynchronously?

Holzchopf

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
500
Hello everyone!

In this thread we learned that mojo2 doesn't implement OnLoading() and the ImagesLoading() method of mojo2's Image is only implemented for html5.

So here's my question:
How do I achieve asynchronous image loading with mojo2 on android?
 
imho you can't. For this you would need threading. Why do you need "asynchronous" loading on Android?
 
Ok thanks.

I have an app that starts with 4s of black screen. Recording and reporting some timestamps showed me that a good portion goes to loading images (and loading sounds, but in the end I'd like to address both sources of lag). At the moment I load them in OnCreate - I'll try moving them to a later point in OnUpdate so I can draw a tiny "loading" or similar on the screen before the lag starts. I'll report later how this worked out.
 
I hope double postings are allowed here.

Now I'm quite happy with this:
- I moved all the asset loading into a function. This function loads just very few assets every time when called, returns true unless it has loaded all assets (they're not loaded asynchronously).
- The app now starts in the "load assets" state
- While in this state, it calls the load function in OnUpdate
- While in this state, it renders a loading screen in OnRender
- Once the load function messages to be done, the app goes leaves the "load assets" state

This results in a somewhat stuttering loading animation, but I prefer having that over having absolutely no "response" during 4s. The method doesn't seem to increase loading times significantly (I couldn't see a significant difference in my logged time between after and before this method).

:):rolleyes:
 
That is what I did whe I experienced lagging. Move the loading to the onupdate method. And there are drew my own loading icon. Worked great!
 
On Android there is this lagging problem when you first draw an image, because it is copied to the graphics memory only when it is drawn, not when loaded. Are you aware of this? Maybe this could also add to your problem.
 
Yes I am aware of this. My approach to this is to immediately draw them once loaded and draw the loading screen on top, so the image is ready and the screen doesn't flicker until the loading (of all media) is complete.
 
I do something really similar, and it's kinda grown out of control. Everything that loads something substantial has something like this:

Code:
Field loadingStage:Int
Field loadingFinished:Bool

Method UpdateLoading:Void()
  loadingStage += 1

  Select loadingStage
  Case 1
    'load some images directly

  Case 2
    'we need to load <asset> which itself has an UpdateLoading function...
    '(stall on this stage until the asset has finished loading)
    If Not asset.loadingFinished Then asset.UpdateLoading() Else loadingStage -= 1

  Case 3
    loadingFinished = True

  End
End

...which really makes me wish I could collapse Case blocks. Sigh.
 
Back
Top Bottom