@@ -20,7 +20,7 @@ let backgroundSharp = null;
2020let backgroundSmooth = null ;
2121
2222// animate each batch of updates for 12 seconds
23- const animationDuration = 12000 ;
23+ const animationDuration = 30000 ;
2424
2525const container = new PIXI . Container ( ) ;
2626// scale and center container initially
@@ -285,11 +285,18 @@ PIXI.Assets.load([
285285 scaleMode : PIXI . SCALE_MODES . NEAREST ,
286286 } ) ;
287287
288- const charOffset = 1 ; // 1 index here gets sprite direction index
288+ // Create texture arrays for each direction
289+ // Down: x=1, Up: x=4, Left: x=6, Right: x=8
290+ let textureCharsDown = [ ] ;
291+ let textureCharsUp = [ ] ;
292+ let textureCharsLeft = [ ] ;
293+ let textureCharsRight = [ ] ;
289294
290- let textureChars = [ ] ;
291295 for ( let i = 0 ; i < 50 ; i ++ ) {
292- textureChars . push ( getSpriteByCoords ( charOffset , i , baseTextureChar ) )
296+ textureCharsDown . push ( getSpriteByCoords ( 1 , i , baseTextureChar ) ) ;
297+ textureCharsUp . push ( getSpriteByCoords ( 4 , i , baseTextureChar ) ) ;
298+ textureCharsLeft . push ( getSpriteByCoords ( 6 , i , baseTextureChar ) ) ;
299+ textureCharsRight . push ( getSpriteByCoords ( 8 , i , baseTextureChar ) ) ;
293300 }
294301
295302
@@ -311,15 +318,15 @@ PIXI.Assets.load([
311318 spriteIdx = parsed ;
312319 }
313320 }
314- const sprite = new PIXI . Sprite ( textureChars [ spriteIdx ] ) ;
315- //sprite.x = charOffset * 40;
321+ const sprite = new PIXI . Sprite ( textureCharsDown [ spriteIdx ] ) ;
322+ //sprite.x = charOffset * 40;
316323 sprite . anchor . set ( 0.5 ) ;
317324 //sprite.scale.set(0.5); // Adjust scale as needed
318325 const subContainer = new PIXI . Container ( ) ;
319326
320327 subContainer . addChild ( sprite ) ;
321328 const label = new PIXI . Text (
322- labelText ,
329+ labelText ,
323330 {
324331 fontFamily : 'Arial' ,
325332 fontSize : 14 ,
@@ -331,7 +338,7 @@ PIXI.Assets.load([
331338 subContainer . addChild ( label ) ;
332339 container . addChild ( subContainer ) ;
333340
334- activeSprites . push ( { subContainer, path, startTime : null } ) ;
341+ activeSprites . push ( { subContainer, sprite , spriteIdx , path, startTime : null } ) ;
335342 }
336343 }
337344
@@ -353,6 +360,29 @@ PIXI.Assets.load([
353360 obj . subContainer . x = 16 * ( currentPoint [ 0 ] + ( nextPoint [ 0 ] - currentPoint [ 0 ] ) * pointProgress ) ;
354361 obj . subContainer . y = 16 * ( currentPoint [ 1 ] + ( nextPoint [ 1 ] - currentPoint [ 1 ] ) * pointProgress ) ;
355362
363+ // Calculate movement direction and update sprite texture
364+ if ( currentIndex !== nextIndex ) {
365+ const dx = nextPoint [ 0 ] - currentPoint [ 0 ] ;
366+ const dy = nextPoint [ 1 ] - currentPoint [ 1 ] ;
367+
368+ // Determine which direction is dominant
369+ if ( Math . abs ( dx ) > Math . abs ( dy ) ) {
370+ // Horizontal movement is dominant
371+ if ( dx > 0 ) {
372+ obj . sprite . texture = textureCharsRight [ obj . spriteIdx ] ;
373+ } else {
374+ obj . sprite . texture = textureCharsLeft [ obj . spriteIdx ] ;
375+ }
376+ } else {
377+ // Vertical movement is dominant
378+ if ( dy > 0 ) {
379+ obj . sprite . texture = textureCharsDown [ obj . spriteIdx ] ;
380+ } else {
381+ obj . sprite . texture = textureCharsUp [ obj . spriteIdx ] ;
382+ }
383+ }
384+ }
385+
356386 if ( progress >= 1 ) {
357387 container . removeChild ( obj . subContainer ) ; // Remove sprite from the scene
358388 obj . subContainer . destroy ( { children : true } ) ; // Optional: frees up memory used by the sprite
0 commit comments