PageRenderTime 22ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

/examples/SDLx/SDLx_sprite.pl

http://github.com/PerlGameDev/SDL
Perl | 46 lines | 35 code | 10 blank | 1 comment | 1 complexity | 4974879f35f50a1ec660fcd8866e0533 MD5 | raw file
 1use strict;
 2use SDL;
 3use SDL::Video;
 4use SDL::Color;
 5use SDL::Rect;
 6use SDL::Surface;
 7use SDL::GFX::Rotozoom;
 8use lib '../lib';
 9use SDLx::Sprite;
10
11SDL::init(SDL_INIT_VIDEO);
12
13my $disp = SDL::Video::set_video_mode( 300, 300, 32, SDL_ANYFORMAT );
14
15my $pixel = SDL::Video::map_RGB( $disp->format, rand(255), rand(255), rand(255) );
16SDL::Video::fill_rect(
17	$disp, SDL::Rect->new( 0, 0, $disp->w, $disp->h ),
18	$pixel
19);
20
21my $sprite = SDLx::Sprite->new( image => 'test/data/chest.png' );
22
23$sprite->alpha_key( SDL::Color->new( 0xfc, 0x00, 0xff ) );
24$sprite->alpha(0.8);
25
26my $angle = 0;
27while ( $angle++ < 360 ) {
28	SDL::Video::fill_rect(
29		$disp, SDL::Rect->new( 0, 0, $disp->w, $disp->h ),
30		$pixel
31	);
32
33	$sprite->rotation($angle);
34
35	#
36	$sprite->draw_xy(
37		$disp,
38		$disp->w / 2 - ( $sprite->w / 2 ),
39		$disp->h / 2 - ( $sprite->h / 2 )
40	);
41
42	SDL::Video::update_rect( $disp, 0, 0, 300, 300 );
43
44	SDL::delay(2);
45}
46SDL::delay(2000);