correctly center airplane
[perl-landing-airplanes.git] / Airplane.pm
index 0b49c85..0078cb4 100644 (file)
@@ -36,10 +36,6 @@ sub draw {
                        $self->{tick} = 0;
                        return;
                }
-               my $to = SDL::Rect->new(
-                       -x => $self->{path}[$pos],
-                       -y => $self->{path}[$pos+1],
-               );
 #              $plane->blit( $plane->rect, $self->{app}, $to );
 
                my $radian = atan2(
@@ -52,6 +48,12 @@ sub draw {
 
                my $plane = SDL::Surface->new( -name => 'artwork/airplane.png' );
                my $rotated = $tool->rotoZoom( $plane, $deg, 1, 1 );
+
+               my $to = SDL::Rect->new(
+                       -x => $self->{path}[$pos]       - $rotated->width / 2,
+                       -y => $self->{path}[$pos+1]     - $rotated->height / 2,
+               );
+
                $rotated->blit( $rotated->rect, $self->{app}, $to );
 
                warn "$pos $radian $deg ", $rotated->width, ' ', $rotated->height;