nfagerlund / bevy-tablestakes

takin a new thing for a spin
0 stars 0 forks source link

Asset importing #2

Closed nfagerlund closed 1 year ago

nfagerlund commented 1 year ago

OK, so assume I'm gonna keep working with these shaunjs sprites. Or, alternately, some other assets I get ahold of. That means I'm starting with (or can at least derive):

What I WANT to have is that, plus:

...with all of the spatial ones measured in offsets from the bottom left corner, since that's the positioning origin.

The problem there is, all of those things are just, like, a social construct, maaannnnn. So I need some way to visually construct them in probably Aseprite, and then export them in a useful format that bevy can use.

So, uh,

nfagerlund commented 1 year ago

Okay, so I'm working with alpine-alpaca/asefile (rather than mdenchev/bevy_aseprite, which is too high-level for what I need).

Aseprite lets you link/reference cels for reduced storage overhead and easier updates of shared content. But it looks like the asefile crate abstracts over that, and presents you an interface that always returns full image content for each cel if you need to dig into pixels. Which is actually probably much nicer to work with! It's just highly redundant, especially since I need box content for every frame. Oh well! Importing can't be in the critical loop, then, but we already knew that.

Also, Cel has a magic .top_left() method that gets me exactly what I want, but it turns out that's an artifact of aseprite's pixel data compression/storage format. It must not be storing the transparent pixels that form the padding of a mostly-transparent cel, and instead just absolutely positioning the first meaningful pixel. So, there's no equivalent .bottom_right(). alas!!!

But, Cel.image().enumerate_pixels() pretty much gets me exactly what I need! The iterator yields the coords and rgba content as a (u32, u32, Rgba([u8; 4])), and if the fourth component of that Rgba is 0 it means it's a transparent pixel.

I just need to do that on every frame of the walkbox et al, and then associate the resulting rect bounds with the actual frame I'm working with. Oh... and also extract the visible image content I want and put it into some texture format bevy can use.

nfagerlund commented 1 year ago
nfagerlund commented 1 year ago

Can I annotate looped / not looped in the aseprite file? Does that make sense? Isaac says he never ended up needing animations that might be both looped and non-looped.

ETA: Ok nope, not today. https://community.aseprite.org/t/userdata-enhancements/4831/5 Noel from exok requested that exact same feature for the same reasons (ah hey, that's validating), and as of early 2022 it's planned but not started.

ETA: Well, the way tutorial boi did it was to handle it in the application code via the state machine and the "act out" trigger function. So even though loopiness probably does inhere in the animation, I'll just do that for now -- the easiest way I can see to tie it to the animation source would be a .meta.ase file or something, and that makes no sense until I have at least two things to put in there.

nfagerlund commented 1 year ago

OK, here we go, next move: refactor existing movement to use the same kinds of rectangles as the assets.

nfagerlund commented 1 year ago

Hmm so this is mostly done, the main thing is looping and emitting finished events.

nfagerlund commented 1 year ago

I did it!