PageRenderTime 41ms CodeModel.GetById 13ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/SDLx/SDLx_sprite_animated.pl

http://github.com/PerlGameDev/SDL
Perl | 45 lines | 35 code | 10 blank | 0 comment | 1 complexity | e892eaf128366e1e9dac737bb1d1071a MD5 | raw file
 1use strict;
 2use SDL;
 3use SDL::Video;
 4use SDL::Color;
 5use SDL::Rect;
 6
 7use SDLx::Sprite::Animated;
 8
 9SDL::init(SDL_INIT_VIDEO);
10
11my $disp = SDL::Video::set_video_mode( 300, 300, 32, SDL_ANYFORMAT );
12
13my $pixel = SDL::Video::map_RGB( $disp->format, 0, 0, 0 );
14SDL::Video::fill_rect(
15	$disp, SDL::Rect->new( 0, 0, $disp->w, $disp->h ),
16	$pixel
17);
18
19my $sprite = SDLx::Sprite::Animated->new(
20	image           => 'test/data/hero.bmp',
21	rect            => SDL::Rect->new( 48, 0, 48, 48 ),
22	ticks_per_frame => 6,
23);
24$sprite->set_sequences( left => [ [ 1, 0 ], [ 1, 1 ], [ 1, 2 ] ], );
25$sprite->alpha_key( SDL::Color->new( 0xff, 0x00, 0xff ) );
26$sprite->sequence('left');
27$sprite->start();
28my $x     = 0;
29my $ticks = 0;
30
31while ( $x++ < 30 ) {
32	SDL::Video::fill_rect(
33		$disp, SDL::Rect->new( 0, 0, $disp->w, $disp->h ),
34		$pixel
35	);
36
37	$sprite->x( $x * 10 );
38	$sprite->next();
39	$sprite->draw($disp);
40
41	SDL::Video::update_rect( $disp, 0, 0, 0, 0 );
42
43	SDL::delay(100);
44}
45