Fix for .vs virtual sprites
This commit is contained in:
parent
48c2854fa2
commit
89a27be3d9
|
|
@ -232,14 +232,9 @@ sub LoadVirtualSprite {
|
|||
|
||||
my @frames = map { GetAsset($_) || return } (@files);
|
||||
my $h = $frames[0]->surface()->height();
|
||||
my $hp = 0;
|
||||
my $w = $frames[0]->surface()->width();
|
||||
|
||||
LogData(INFO, sprintf("Format = '%s', Pitch = '%s'",
|
||||
$frames[0]->surface()->format(),
|
||||
));
|
||||
exit(0);
|
||||
|
||||
my $newsurface = SDLx::Surface->new( width => $frames[0]->surface()->width(),
|
||||
my $newsurface = SDLx::Surface->new( width => $w,
|
||||
height => $h * (@frames-0),
|
||||
format => $frames[0]->surface()->format(),
|
||||
pitch => $frames[0]->surface()->pitch(),
|
||||
|
|
@ -247,14 +242,19 @@ sub LoadVirtualSprite {
|
|||
color => [0, 0, 0, 255],
|
||||
);
|
||||
|
||||
#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( $_->surface(), $f, 0);
|
||||
$_->draw_xy($newsurface, 0, $hp);
|
||||
$hp += $h;
|
||||
my $dest_row = 0;
|
||||
my $dst_format = $newsurface->format();
|
||||
foreach my $src (@frames) {
|
||||
my $format = $src->surface()->format();
|
||||
for(my $y = 0; $y < $h; $y++, $dest_row++) {
|
||||
for(my $x = 0; $x < $w; $x++) {
|
||||
my $pixel = $src->surface()->get_pixel( $y, $x );
|
||||
my $c = SDL::Video::get_RGBA( $format, $pixel );
|
||||
my $c2 = SDL::Video::map_RGBA( $dst_format, @$c );
|
||||
$newsurface->set_pixel( $dest_row, $x, $c2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
#SDL::Video::set_alpha($newsurface, $f, 0);
|
||||
|
||||
my $anim = SDLx::Sprite::Animated->new( surface => $newsurface,
|
||||
width => $newsurface->width(),
|
||||
|
|
@ -268,18 +268,5 @@ sub LoadVirtualSprite {
|
|||
return $anim;
|
||||
}
|
||||
|
||||
# Flip surface left to right -- Returns new surface
|
||||
sub FlipSurface {
|
||||
my($surface) = @_;
|
||||
my $new = SDLx::Surface->new( width => $surface->width(),
|
||||
height => $surface->height(),
|
||||
);
|
||||
|
||||
for(my $x=0; $x < $surface->width(); $x++) {
|
||||
my $x2 = $surface->width() - $x - 1;
|
||||
$surface->blit( [ $x, 0, 1, $surface->height() ], $new, [ $x2, 0, 1, $surface->height() ] );
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ sub ShowSprite {
|
|||
} elsif($name eq 'max_loops') {
|
||||
$a->max_loops($val);
|
||||
} elsif($o eq 'flip') {
|
||||
# Don't want to flip back and forth every time
|
||||
UnloadAsset($file);
|
||||
my $s=$a->surface();
|
||||
$a->surface( FlipSurface($s) );
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ __init__:
|
|||
Define TestVar 1
|
||||
|
||||
Show aka spritesheet.png 0 0 1 flip
|
||||
Show aka2 spritesheet.png 100 0 2 Reverse
|
||||
Show aka3 spritesheet.png 200 0 3 max_loops=10
|
||||
Show aka2 aka.vs 100 0 2
|
||||
Show aka3 aka.vs 200 0 3 Reverse flip
|
||||
Show aka4 spritesheet.png 300 0 1 max_loops=1
|
||||
|
||||
AddSayer h "Hermione" aka01.png 200 200 200 255 flip
|
||||
AddSayer h2 "Topless\ Hermione" aka05.png 255 0 0 255
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
.vs constructed animated sprites don't respect source image's alpha channel
|
||||
Loading…
Reference in New Issue