package SDLx::Sprite::AnimatedFiles;
use strict;
use warnings;

use SDL;
use SDLx::Surface;
use SDLx::Sprite;

use base 'SDLx::Sprite::Animated';

sub new
{
    my ( $class, %options ) = @_;

    if('ARRAY' eq ref $options{image})
    {
        my $images = delete $options{image};
        my @sprite;
        my $width  = 0;
        my $height = 0;

        for my $image (@$images)
        {
            my $sprite = SDLx::Sprite->new(image => $image, x => $width, y => 0);
#            $sprite->surface->draw_rect( SDL::Rect->new(0,0,100,100), 0xFF00FFFF );
            push @sprite, $sprite;
            $width += $sprite->w;
            $height = $sprite->h if $height < $sprite->h;
        }

        my $full = SDLx::Surface->new(width=>$width, height=>$height);
        $_->surface->blit($full) for @sprite;

#        $full->draw_rect( SDL::Rect->new(100,0,100,100), 0xFF00FFFF );

        $options{surface} = $full->surface;
        $options{step_x}  = $sprite[0]->w;
        $options{step_y}  = $sprite[0]->h;
    }

    return $class->SUPER::new(%options);
}

1;


