actionscript 3 - How to animate a spritesheet without an atlas? -


i have sprite sheet 30 frames of different animations not in order.

i use starling make animations not have / don't have time make atlas xml. if did, rather not use atlas.

furthermore, sprite sheet has black background , examples researched have transparent background.

any appreciated. thanks.

here example on how retrieve textures atlas giving frames want , frames width , height:

package {     import starling.textures.texture;     import flash.geom.rectangle;      public class animfromatlas     {         public function animfromatlas( )         {          }          public static function texturesfromatlas( atlas:texture, frames:array, framewidth:int, frameheight:int ):vector.<texture>         {             // declare x , y properties              var x:int, y:int = 0;             // create base rectangle flrame width , frame height, have update x , y values.             var region:rectangle = new rectangle( 0, 0, framewidth, frameheight );             // create texture vector have return             var textures:vector.<texture> = new <texture>[];             // calculate max frame on 1 line on atlas             var framesonline:int = atlas.width / framewidth;              // loop frames textures on atlas             for( var i:int = 0; i<frames.length; ++i )             {                 x = (int( (frames[i] % framesonline) ) * framewidth);                    y = (int( (frames[i] / framesonline) ) * frameheight);                 region.x = x;                 region.y = y;                 textures[i] = texture.fromtexture(atlas, region);                  trace( region );             }              // fix vector better performances             textures.fixed = true;              // return textures             return textures;         }     } } 

so have call static method animfromatlas.texturesfromatlas(yourspritesheet, [1,2,5,8,3], 150, 100);

if have atlas bitmap , not texture can use texture.frombitmap(yourbitmap) texture.

i didn't tried maybe don't work want think should trick, added trace of rectangles found textures can see if seems credible or not.

for black background, can directly as3 this:

var bitmapdata:bitmapdata = youratlasbitmap.bitmapdata; var black     :uint = 0xff000000;  // black color replace var trans     :uint = 0x00000000;  // transparent color replace black var mask      :uint = 0xffffffff;  // mask use (i use white here) // target rectangle var rect      :rectangle = new rectangle( 0, 0, bitmapdata.width, bitmapdata.height );  // replacement of color bitmapdata.threshold( bitmapdata, rect, new point(0,0), "==", black, trans, mask, true );  // create new bitmap new bitmapdata var yournewbitmap:bitmap = new bitmap(bitmapdata); 

i hope you.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -