Author Topic: One FlxSprite - several animations in different files  (Read 1068 times)

Elegar

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Hello everybody!
Is it possible to load animations from different files to one FlxSprite object?
For example: I have actor:FlxSprite , and I have several files go.png, stand.png etc... Each of those files contains number of frames. So I looking for something like
Code: [Select]
actor.loadGraphic(img_go, true);
actor.loadGraphic(img_stand, true);
But in this way every next loaded graphic will replace previous one when I don't need it to be done.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: One FlxSprite - several animations in different files
« Reply #1 on: Mon, Jan 9, 2012 »
Nope. Either stick them all together into a single sprite sheet, or use an FlxGroup that contains several sprites (a "standing" one, etc). Personally I'd try and combine them first.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

eduardonunesp

  • Member
  • **
  • Posts: 55
  • Karma: +0/-0
    • View Profile
    • Blog Dream Escape.
Re: One FlxSprite - several animations in different files
« Reply #2 on: Fri, Jan 13, 2012 »
Ok, extends FlxSprite then add this method,  i do not test yet and maybe have erros, but i will test

Code: [Select]
        public function loadGraphics(Graphic:Array, Animated:Boolean=false, Reverse:Boolean=false, Width:uint=0, Height:uint=0, Unique:Boolean=false):FlxSprite {   
            _bakedRotation = 0;
               
            for(var i:uint = 0; i < Graphic.lenght;i++) {
                var tmpPixels:BitmapData = FlxG.addBitmap(Graphic[i], Reverse, Unique);
                _pixels.merge(tmpPixels, new Rectangle(0, 0, tmpPixels.width, tmpPixels.height), new Point(_pixels.width, 0), 0, 0, 0, 0);
            }   

            if(Reverse)
                _flipped = _pixels.width>>1;
            else
                _flipped = 0;
            if(Width == 0)
            {   
                if(Animated)
                    Width = _pixels.height;
                else if(_flipped > 0)
                    Width = _pixels.width*0.5;
                else
                    Width = _pixels.width;
            }   
            width = frameWidth = Width;
            if(Height == 0)
            {   
                if(Animated)
                    Height = width;
                else
                    Height = _pixels.height;
            }   
            height = frameHeight = Height;
            resetHelpers();
            return this;
        }   


To is just:

Code: [Select]
loadGraphics([Asset.image1, Asset.image2], true);