@@ -134,6 +134,10 @@ async fn run() -> Result<()> {
134134 log:: info!( "Starting video encoder..." ) ;
135135 let mut encoder = ProResEncoder :: new ( & args. output , args. width , args. height , args. fps ) ?;
136136
137+ // Track last direction for each run
138+ let mut run_directions: Vec < sprite_video_renderer:: data:: Direction > =
139+ vec ! [ sprite_video_renderer:: data:: Direction :: Down ; runs. len( ) ] ;
140+
137141 // Render frames
138142 log:: info!( "Rendering {} frames..." , total_frames) ;
139143 let start_time = std:: time:: Instant :: now ( ) ;
@@ -144,7 +148,7 @@ async fn run() -> Result<()> {
144148 // Calculate sprite instances for this frame
145149 let mut sprite_instances = Vec :: new ( ) ;
146150
147- for run in & runs {
151+ for ( run_idx , run) in runs. iter ( ) . enumerate ( ) {
148152 // Calculate which coord index we're at (using all coords, just faster)
149153 let coord_index = ( time_ms / effective_interval_ms) as usize ;
150154
@@ -180,19 +184,25 @@ async fn run() -> Result<()> {
180184 current_pos[ 1 ] + ( next_pos[ 1 ] - current_pos[ 1 ] ) * interp_t - 8.0 ,
181185 ] ;
182186
183- // Determine direction
187+ // Determine direction - only update if there's movement
184188 let dx = next_pos[ 0 ] - current_pos[ 0 ] ;
185189 let dy = next_pos[ 1 ] - current_pos[ 1 ] ;
186- let direction = if dx. abs ( ) > dy. abs ( ) {
187- if dx > 0.0 { sprite_video_renderer:: data:: Direction :: Right }
188- else { sprite_video_renderer:: data:: Direction :: Left }
189- } else {
190- if dy > 0.0 { sprite_video_renderer:: data:: Direction :: Down }
191- else { sprite_video_renderer:: data:: Direction :: Up }
192- } ;
190+
191+ if dx. abs ( ) > 0.1 || dy. abs ( ) > 0.1 {
192+ // There's movement, calculate new direction
193+ let new_direction = if dx. abs ( ) > dy. abs ( ) {
194+ if dx > 0.0 { sprite_video_renderer:: data:: Direction :: Right }
195+ else { sprite_video_renderer:: data:: Direction :: Left }
196+ } else {
197+ if dy > 0.0 { sprite_video_renderer:: data:: Direction :: Down }
198+ else { sprite_video_renderer:: data:: Direction :: Up }
199+ } ;
200+ run_directions[ run_idx] = new_direction;
201+ }
202+ // else: no movement, keep the stored direction
193203
194204 // Get texture coordinates
195- let tex_coords = texture_atlas. get_sprite_tex_coords ( run. sprite_id , direction ) ;
205+ let tex_coords = texture_atlas. get_sprite_tex_coords ( run. sprite_id , run_directions [ run_idx ] ) ;
196206
197207 sprite_instances. push ( SpriteInstance {
198208 position,
0 commit comments