From c7136d010c8bb53794fb81933487a4e1f3c1cb7f Mon Sep 17 00:00:00 2001 From: Ryan Shepherd Date: Mon, 24 Sep 2018 10:18:35 -0400 Subject: [PATCH] Changes to simplify LoadVirtualSprite --- PerlRPG/Assets.pm | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/PerlRPG/Assets.pm b/PerlRPG/Assets.pm index 0e1058c..10d7c99 100644 --- a/PerlRPG/Assets.pm +++ b/PerlRPG/Assets.pm @@ -181,32 +181,31 @@ sub LoadVirtualSprite { return $files{$name}; } - foreach (@files) { - if(!LoadAsset($_)) { - LogData(ERROR, "Unable to load virtual sprite, error loading one or more assets."); - return undef; - } - LogData(DEBUG, "Adding asset $_ to virtual sprite $name"); - } - - my @frames = map { $files{$_}{'Sprite'}->surface() } (@files); - my $h = $frames[0]->height(); + my @frames = map { GetAsset($_) || return } (@files); + my $h = $frames[0]->surface()->height(); my $hp = 0; - - my $newsurface = SDLx::Surface->new( width => $frames[0]->width(), + + LogData(INFO, sprintf("Format = '%s', Pitch = '%s'", + $frames[0]->surface()->format(), + )); + exit(0); + + my $newsurface = SDLx::Surface->new( width => $frames[0]->surface()->width(), height => $h * (@frames-0), - format => $frames[0]->format(), - pitch => $frames[0]->pitch(), - flags => $frames[0]->flags(), + format => $frames[0]->surface()->format(), + pitch => $frames[0]->surface()->pitch(), + flags => $frames[0]->surface()->flags(), + color => [0, 0, 0, 255], ); - $newsurface->draw_rect( [0, 0, $newsurface->width(), $newsurface->height()], [0, 0, 0, 255]); - #SDL::Video::set_alpha( $newsurface, SDL::Video::SDL_SRCALPHA, 0); + + #SDL::Video::set_alpha($newsurface, SDL::Video::SDL_RLEACCEL, 0); + #my $f = SDL::Video::SDL_SRCALPHA | SDL::Video::SDL_RLEACCEL; foreach (@frames) { - #SDL::Video::set_alpha( $_, SDL::Video::SDL_SRCALPHA, 255); - #FIXME - This call ignores the source alpha channel - $_->blit( $newsurface, undef, [0, $hp, $_->width(), $_->height()]); + #SDL::Video::set_alpha( $_->surface(), $f, 0); + $_->draw_xy($newsurface, 0, $hp); $hp += $h; } + #SDL::Video::set_alpha($newsurface, $f, 0); my $anim = SDLx::Sprite::Animated->new( surface => $newsurface, width => $newsurface->width(), @@ -220,5 +219,4 @@ sub LoadVirtualSprite { return $anim; } - 1;