Advertisement
Chidubemmo

BGSprite.hx

Jul 22nd, 2023
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.02 KB | None | 0 0
  1. package;
  2.  
  3. import flixel.FlxSprite;
  4. import flixel.graphics.frames.FlxAtlasFrames;
  5.  
  6. class BGSprite extends FlxSprite
  7. {
  8.     private var idleAnim:String;
  9.  
  10.     //I hate StageData when library didn't select it or anything :/
  11.     public function new(image:String, ?library:String, x:Float = 0, y:Float = 0, ?scrollX:Float = 1, ?scrollY:Float = 1, ?animArray:Array<String> = null, ?loop:Bool = false) {
  12.         super(x, y);
  13.  
  14.         if (animArray != null) {
  15.             frames = Paths.getSparrowAtlas(image, library);
  16.             for (i in 0...animArray.length) {
  17.                 var anim:String = animArray[i];
  18.                 animation.addByPrefix(anim, anim, 24, loop);
  19.                 if(idleAnim == null) {
  20.                     idleAnim = anim;
  21.                     animation.play(anim);
  22.                 }
  23.             }
  24.         } else {
  25.             if(image != null) {
  26.                 loadGraphic(Paths.image(image, library));
  27.             }
  28.             active = false;
  29.         }
  30.         scrollFactor.set(scrollX, scrollY);
  31.         antialiasing = ClientPrefs.globalAntialiasing;
  32.     }
  33.  
  34.     public function dance(?forceplay:Bool = false) {
  35.         if(idleAnim != null) {
  36.             animation.play(idleAnim, forceplay);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement