Fwd: Can`t draw sprite on another sprite

[email protected] ("Roman V. Nikolaev") Thu, 24 Mar 2011 11:12:06 +0300
Newsgroups perl.sdl.devel
Message-ID <[email protected]>
How?
I was use SDLx::Sprite::Animated, but my images in separate files like:
unit-run1.png, unit-run2.png, unit-run3.png, ...
I make simple child (in attach) but this strings not work:

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

I try SDLx::Sprite->draw but it not work too. I think I go to wrong way.
Please help me to do this.

P.S. What you think: this code (with fixes) can be added later in
SDLx::Sprite::Animated?


Roman V. Nikolaev
AnimatedFiles.pm (application/x-perl, 1.1 KB)
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;
signature.asc (application/pgp-signature, 262 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2K/NoACgkQ6hKpBt4OHBvalgCfWBWBSflFDBZCLRrD6dgmja8P
g1UAn2vpWPfTtLdEmtVr+f8Uj0p5cEUI
=qCn5
-----END PGP SIGNATURE-----