From e1d0817a5bbbff49f288c0a46ac84ea5cf6041ae Mon Sep 17 00:00:00 2001 From: Ryan Shepherd Date: Mon, 1 Oct 2018 11:27:42 -0400 Subject: [PATCH] Add FlipSurface function --- PerlRPG/Assets.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/PerlRPG/Assets.pm b/PerlRPG/Assets.pm index 5d4895a..7dfb793 100644 --- a/PerlRPG/Assets.pm +++ b/PerlRPG/Assets.pm @@ -268,4 +268,18 @@ 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;