#Move sprite "on become visible"?

4 messages · Page 1 of 1 (latest)

sly finch
#

Im just working through some beginner tutorials, and added an asset loader. Is there some kind of way to create an "on will become visible" on a sprite, so that I can then get the image size to do the math on how far from the edge to place the sprite?

I understand its possible to add a "loading screen" of sorts. I just wonder if its also possible to keep it simple and just move/place the sprite once its ready to appear proper.

nocturne leaf
#

Bevy cheat book has a chapter on loading progress tracking with resource that keeps handles to not yet loaded assets. You can use it and emit your own custom events when image is fully loaded and then handle those events in your specialized systems(or just skip events and handle it directly in the same system that tracks progress): https://bevy-cheatbook.github.io/assets/ready.html (It's a little outdated so you may need to check currend docs on the relevants elements)

sly finch
#

Thanks Arrekin, the example suggests that polling might be needed to repeatedly check if a list of things are ready. I guess I was wondering if its possible to just bypass a loading screen and code to wait for loading. Is it not possible to add an event handler of sorts, that is just called when individual item becomes ready to display. Or is it the case that there is no "event", its simply the case that (in the main update loop) before a sprite is loaded it cant be drawn and once its loaded its now drawn.

nocturne leaf
#

When you request asset you get handle to represent the asset and it's state. The loading process is async and can happen over many frames so you are right in that the image is just not drawn until it is fully loaded(but the game loop continues normally so your program does not freeze for seconds). You can extend it any way you want but there is no "block everything until game is loaded", you need to implement your own loading state and then when you are happy move to 'playing' state.