mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
reuse dynamic sprite
This commit is contained in:
parent
b99fff7c8e
commit
87ac2fe53c
|
@ -82,6 +82,12 @@ impl WorkingLetter {
|
|||
x_offset: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn reset(&mut self) {
|
||||
self.x_position = 0;
|
||||
self.x_offset = 0;
|
||||
self.dynamic.clear(0);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Configuration {
|
||||
|
@ -177,15 +183,18 @@ impl WordRender<'_> {
|
|||
}
|
||||
|
||||
fn finalise_letter(&mut self) {
|
||||
let mut final_letter = WorkingLetter::new(self.config.sprite_size);
|
||||
core::mem::swap(&mut final_letter, &mut self.working.letter);
|
||||
|
||||
let sprite = final_letter.dynamic.to_vram(self.config.palette.clone());
|
||||
let sprite = self
|
||||
.working
|
||||
.letter
|
||||
.dynamic
|
||||
.to_vram(self.config.palette.clone());
|
||||
self.working.meta.letters.push(LetterGroup {
|
||||
sprite,
|
||||
offset: self.working.word_offset,
|
||||
});
|
||||
self.working.word_offset += final_letter.x_position;
|
||||
self.working.word_offset += self.working.letter.x_position;
|
||||
|
||||
self.working.letter.reset();
|
||||
}
|
||||
|
||||
fn render_char(&mut self, c: char) {
|
||||
|
|
|
@ -345,6 +345,13 @@ impl<A: Allocator> DynamicSprite<A> {
|
|||
self.data[byte_to_modify] = byte;
|
||||
}
|
||||
|
||||
/// Wipes the sprite
|
||||
pub fn clear(&mut self, paletted_pixel: usize) {
|
||||
assert!(paletted_pixel < 0x10);
|
||||
let reset = (paletted_pixel | paletted_pixel << 4) as u8;
|
||||
self.data.fill(reset);
|
||||
}
|
||||
|
||||
/// Tries to copy the sprite to vram to be used to set object sprites.
|
||||
pub fn try_vram(&self, palette: PaletteVram) -> Result<SpriteVram, LoaderError> {
|
||||
SpriteVram::new(&self.data, self.size, palette)
|
||||
|
|
Loading…
Reference in a new issue