#!/usr/bin/perl use strict; use warnings; use Image::Magick; use SDL; use SDL::App; use SDL::Surface; use SDL::Color; use SDL::Rect; use Data::Dumper; my $app = SDL::App->new( -title=>"Sprite Test", -width =>100, -height => 100, -depth => 24, ); my $sprite = load_sprites(-file=>"testlight-a.gif"); my $app_rect = SDL::Rect->new( -height => 480, -width => 600, -x => 0, + -y => 0 ) or die "Couldn't create SDL::Rect !"; for (0..100){ for my $im ( @{ $sprite->{-frames} } ){ $im->blit( $sprite->{-src_rect} ,$app, $sprite->{-src_rect}); #s +rc = src = not work. #$im->blit( $sprite->{-src_rect} ,$app, $sprite->{-dst_rect}); # +src = dst = works $app->update($sprite->{-src_rect}); $app->delay(200); } } #------------------------------------------------------------- # # Oddities: # If Surface not initialized via graphic file, blits will not take. # Image::Magick->Write is succeeding but not returning count of images + written. sub load_sprites { my %args = ( -file => undef, -tmpfile => '/tmp/sprite-im.gif', @_, ); die "File [$args{-file}] doesn't exist!" unless -e $args{-file}; my ($src_rect,$dst_rect, $magick, @frames, $x ); $magick = Image::Magick->new() or die "Couldn't create Image::Ma +gick object!: $!"; $magick->Read($args{-file}) ; my ($iw,$ih) = $magick->Get( qw /width height/) ; # Get the height + and width of image $src_rect = SDL::Rect->new( -height => $ih, -width => $iw, -x => 0 +, -y => 0 ) or die "Couldn't create SDL::Rect !"; $dst_rect = SDL::Rect->new( -height => $ih, -width => $iw, -x => 0 +, -y => 0 ) or die "Couldn't create SDL::Rect !"; foreach my $im (@$magick) { my ($w,$h,$ws,$hs); # Width, height, start of bounding box, # don't know if this returns valid info fo +r all formats. if ($im->Get( qw /width height bounding-box/ )=~m/^(\d+)x(\d+) +\+(\d+)\+(\d)/){ ($w,$h,$ws,$hs) = ($1,$2,$3,$4); warn join(", ",($w,$h,$ws,$hs)); }else{ die "Error retrieving image properties!"; } # For newer perls, could probably skip the tmp file altogther +and read/write a scalar $im->Write( filename => $args{-tmpfile}); # Isn't returning the count. According to the docs, should be +number of images written so can't error check. push @frames, SDL::Surface->new( -name => $args{-tmpfile}) ; } return { -frames=>\@frames, -x=>0, -y=>0, -src_rect=>$src_rect,-ds +t_rect=>$dst_rect}; }
In reply to Re^2: SDL Surfaces and Rectangles
by shotgunefx
in thread SDL Surfaces and Rectangles
by shotgunefx
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |