mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 00:31:34 +11:00
Merge pull request #269 from corwinkuiper/non-square-sprites
Non square sprites
This commit is contained in:
commit
6f154b2600
|
@ -115,15 +115,17 @@ pub fn include_aseprite_inner(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
for frame in frames {
|
for frame in frames {
|
||||||
let width = frame.width();
|
let width = frame.width();
|
||||||
assert!(width == frame.height() && width.is_power_of_two() && width <= 64);
|
let height = frame.height();
|
||||||
|
assert!(
|
||||||
|
valid_sprite_size(width, height),
|
||||||
|
"File {} contains sprites with unrepresentable size {}x{}",
|
||||||
|
filename.display(),
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
);
|
||||||
|
|
||||||
let image = Image::load_from_dyn_image(frame);
|
let image = Image::load_from_dyn_image(frame);
|
||||||
add_to_optimiser(
|
add_to_optimiser(&mut optimiser, &image, 8, Some(transparent_colour));
|
||||||
&mut optimiser,
|
|
||||||
&image,
|
|
||||||
width as usize,
|
|
||||||
Some(transparent_colour),
|
|
||||||
);
|
|
||||||
images.push(image);
|
images.push(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +295,7 @@ fn palete_tile_data(
|
||||||
let mut tile_data = Vec::new();
|
let mut tile_data = Vec::new();
|
||||||
|
|
||||||
for image in images {
|
for image in images {
|
||||||
let tile_size = image.height;
|
let tile_size = 8;
|
||||||
let tiles_x = image.width / tile_size;
|
let tiles_x = image.width / tile_size;
|
||||||
let tiles_y = image.height / tile_size;
|
let tiles_y = image.height / tile_size;
|
||||||
|
|
||||||
|
@ -401,3 +403,21 @@ mod tests {
|
||||||
assert_eq!(AnimationDirection::PingPong as usize, 2);
|
assert_eq!(AnimationDirection::PingPong as usize, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn valid_sprite_size(width: u32, height: u32) -> bool {
|
||||||
|
match (width, height) {
|
||||||
|
(8, 8) => true,
|
||||||
|
(16, 16) => true,
|
||||||
|
(32, 32) => true,
|
||||||
|
(64, 64) => true,
|
||||||
|
(16, 8) => true,
|
||||||
|
(32, 8) => true,
|
||||||
|
(32, 16) => true,
|
||||||
|
(64, 32) => true,
|
||||||
|
(8, 16) => true,
|
||||||
|
(8, 32) => true,
|
||||||
|
(16, 32) => true,
|
||||||
|
(32, 64) => true,
|
||||||
|
(_, _) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
BIN
agb/examples/gfx/tall.aseprite
Normal file
BIN
agb/examples/gfx/tall.aseprite
Normal file
Binary file not shown.
BIN
agb/examples/gfx/wide.aseprite
Normal file
BIN
agb/examples/gfx/wide.aseprite
Normal file
Binary file not shown.
|
@ -8,7 +8,9 @@ use alloc::vec::Vec;
|
||||||
|
|
||||||
const GRAPHICS: &Graphics = agb::include_aseprite!(
|
const GRAPHICS: &Graphics = agb::include_aseprite!(
|
||||||
"examples/gfx/objects.aseprite",
|
"examples/gfx/objects.aseprite",
|
||||||
"examples/gfx/boss.aseprite"
|
"examples/gfx/boss.aseprite",
|
||||||
|
"examples/gfx/wide.aseprite",
|
||||||
|
"examples/gfx/tall.aseprite"
|
||||||
);
|
);
|
||||||
const SPRITES: &[Sprite] = GRAPHICS.sprites();
|
const SPRITES: &[Sprite] = GRAPHICS.sprites();
|
||||||
const TAG_MAP: &TagMap = GRAPHICS.tags();
|
const TAG_MAP: &TagMap = GRAPHICS.tags();
|
||||||
|
@ -102,6 +104,8 @@ fn main(mut gba: agb::Gba) -> ! {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
all_tags(&gfx);
|
all_tags(&gfx);
|
||||||
|
gfx.commit();
|
||||||
all_sprites(&gfx);
|
all_sprites(&gfx);
|
||||||
|
gfx.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,9 +163,7 @@ macro_rules! align_bytes {
|
||||||
|
|
||||||
/// Includes sprites found in the referenced aseprite files. Can include
|
/// Includes sprites found in the referenced aseprite files. Can include
|
||||||
/// multiple at once and optimises palettes of all included in the single call
|
/// multiple at once and optimises palettes of all included in the single call
|
||||||
/// together. Currently limited to square sprites that match a supported
|
/// together. See [Size] for supported sizes. Returns a reference to [Graphics].
|
||||||
/// dimension of the GBA, see [Size] for supported sizes. Returns a reference to
|
|
||||||
/// [Graphics].
|
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # #![no_std]
|
/// # #![no_std]
|
||||||
|
|
Loading…
Reference in a new issue