/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

  1. use strict;
  2. use SDL;
  3. use SDL::Video;
  4. use SDL::Color;
  5. use SDL::Rect;
  6. use SDL::Surface;
  7. use SDL::GFX::Rotozoom;
  8. use lib '../lib';
  9. use SDLx::Sprite;
  10. SDL::init(SDL_INIT_VIDEO);
  11. my $disp = SDL::Video::set_video_mode( 300, 300, 32, SDL_ANYFORMAT );
  12. my $pixel = SDL::Video::map_RGB( $disp->format, rand(255), rand(255), rand(255) );
  13. SDL::Video::fill_rect(
  14. $disp, SDL::Rect->new( 0, 0, $disp->w, $disp->h ),
  15. $pixel
  16. );
  17. my $sprite = SDLx::Sprite->new( image => 'test/data/chest.png' );
  18. $sprite->alpha_key( SDL::Color->new( 0xfc, 0x00, 0xff ) );
  19. $sprite->alpha(0.8);
  20. my $angle = 0;
  21. while ( $angle++ < 360 ) {
  22. SDL::Video::fill_rect(
  23. $disp, SDL::Rect->new( 0, 0, $disp->w, $disp->h ),
  24. $pixel
  25. );
  26. $sprite->rotation($angle);
  27. #
  28. $sprite->draw_xy(
  29. $disp,
  30. $disp->w / 2 - ( $sprite->w / 2 ),
  31. $disp->h / 2 - ( $sprite->h / 2 )
  32. );
  33. SDL::Video::update_rect( $disp, 0, 0, 300, 300 );
  34. SDL::delay(2);
  35. }
  36. SDL::delay(2000);