diff --git a/src/reskit/level/system.rs b/src/reskit/level/system.rs index cbf25be..fed6f94 100644 --- a/src/reskit/level/system.rs +++ b/src/reskit/level/system.rs @@ -285,9 +285,12 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap ) let sprite_id = sprite_ids.get( &sprite_metadata.id ).ok_or( format!( "invalid file: undefined sprite id \"{}\"", sprite_metadata.id ) )?; result.extend( sprite_id.to_be_bytes() ); + let tiles_across = sprite.image.width() / 8; + let frames: u16 = ( tiles_across / ( sprite_metadata.width as u32 ) ) as u16; + let tile_index_location = tiles_before + tiles_after; result.extend( ( tile_index_location as u16 ).to_be_bytes() ); - tiles_after += ( sprite_metadata.width * sprite_metadata.height ) as u32; + tiles_after += ( ( sprite_metadata.width as u16 * sprite_metadata.height as u16 ) * frames ) as u32; result.push( sprite_metadata.width ); @@ -297,8 +300,6 @@ pub fn get_sprites( tilemap: &TiledTilemap, sprite_ids: &HashMap ) // One animation per .tsx file // Animations run like a filmstrip across, never down - let tiles_across = sprite.image.width() / 8; - let frames: u16 = ( tiles_across / ( sprite_metadata.width as u32 ) ) as u16; result.extend( frames.to_be_bytes() ); if let Some( jiffies ) = sprite_metadata.anim_interval {