/lib/pods/SDLx/LayerManager.pod

http://github.com/PerlGameDev/SDL · Unknown · 166 lines · 92 code · 74 blank · 0 comment · 0 complexity · ec0b8736535b4e5057c84be4f4e4d01f MD5 · raw file

  1. =head1 NAME
  2. SDLx::LayerManager - Extension for managing layers in a 2D world
  3. =head1 CATEGORY
  4. Extension
  5. =head1 SYNOPSIS
  6. use SDLx::Layer;
  7. use SDLx::LayerManager;
  8. use SDL::Image;
  9. use SDL::Surface;
  10. use SDL::Video;
  11. # creating layers
  12. my $layer1 = SDLx::Layer->new( SDL::Image::load('image1.png'), {userdata => '7'} );
  13. my $layer2 = SDLx::Layer->new( SDL::Image::load('image2.png'), 100, 200, {userdata => '42'} );
  14. # creating the manager that holds the layers
  15. my $layermanager = SDLx::LayerManager->new();
  16. $layermanager->add( $layer1 );
  17. $layermanager->add( $layer2 );
  18. my $display = # create your video surface here
  19. $layermanager->blit( $display );
  20. # accessing the layer at point(x,y)
  21. print( $layermanager->by_position( 150, 200 )->data->{userdata} ); # should print '42'
  22. =head1 DESCRIPTION
  23. SDLx::LayerManager is a package to handle a bunch of layers. A layer (see SDLx::Layer) is an SDL::Surface, the position of the surface on screen and some additional information.
  24. The layermanager gives you the opportunity to obtain the layer at a given point on screen and get the layers that are ahead or behind a layer.
  25. You will even be able to attach one or more layers to the mouse, e.g. for simulation some drag&drop functionality.
  26. =head1 METHODS
  27. =head2 new
  28. my $layermanager = SDLx::LayerManager->new();
  29. This creates your layermanager object. It doesn't take any parameters.
  30. =head2 add
  31. $layermanager->add( $layer );
  32. $layermanager->add( SDLx::Layer->new( $surface, $x, $y, $options ) );
  33. Call C<add> to push an SDLx::Layer object to the layermanager.
  34. =head2 layers
  35. my @layers = @{ $layermanager->layers };
  36. my $first_layer = $layermanager->layers->[0];
  37. The method C<layers> returns all layers that were added before.
  38. =head2 layer
  39. my $layer = $layermanager->layer( $index );
  40. To obtain only one layer at index C<$index> use this function. C<$index> ranges from C<0> to C<length - 1>.
  41. =head2 length
  42. my $length = $layermanager->length();
  43. This method returns the count of the added layers.
  44. =head2 blit
  45. $layermanager->blit( $surface );
  46. This method blits all layers to the surface (e.g. your video surface).
  47. =head2 by_position
  48. my $layer = $layermanager->by_position( $x, $y );
  49. C<by_position> returns the C<SDLx::Layer> object at point C<$x $y>, which is not fully transparent at this pixel.
  50. =head2 ahead
  51. my @layers = @{ $layermanager->ahead( $index ) };
  52. This method returns all layers that are ahead of the given layer indicated by C<$index>.
  53. Ahead means that a layer has a higher z-index and is blitted over the given layer.
  54. B<Note>: This method doesn't check for transparency. This will change in future versions.
  55. =head2 behind
  56. my @layers = @{ $layermanager->behind( $index ) };
  57. This method returns all layers that are behind of the given layer indicated by C<$index>.
  58. Behind means that a layer has a lower z-index and is blitted before the given layer.
  59. B<Note>: This method doesn't check for transparency. This will change in future versions.
  60. =head2 attach
  61. $layermanager->attach( $layer, $x, $y );
  62. $layermanager->attach( @layers, $x, $y );
  63. This function makes the given layer(s) sticky to the mouse. If you move the mouse the layer(s) will follow.
  64. The layermanager blits these layers at last, so they will appear on top of all layers.
  65. C<$x> and C<$y> should be set to the coords of the mouse, e.g. the coords of the mouse click.
  66. If you omit C<$x> and C<$y> the layermanager obtains them via SDL::Events::get_mouse_state.
  67. B<Note>: The z-index is not changed for the given layers.
  68. =head2 detach_xy
  69. $layermanager->detach_xy( $x, $y );
  70. C<detach_xy> detaches the previously attached layers to the given coords. The upper left corner of the backmost layer will be at C<$x> and C<$y>.
  71. The other layers are positioned relative to the backmost layer just like before.
  72. =head2 detach_back
  73. $layermanager->detach_back( );
  74. C<detach_back> detaches the previously attached layers back to the position where they were attached.
  75. =head2 foreground
  76. $layermanager->foreground( $layer );
  77. $layermanager->foreground( @layers );
  78. This method moves the given layer(s) to the foreground so that they are blitted on top of the other layers.
  79. =head1 BUGS
  80. Report at sdlperl.ath.cx
  81. =head1 SUPPORT
  82. #sdl irc.perl.org
  83. =head1 AUTHORS
  84. See L<SDL/AUTHORS>.
  85. =head1 COPYRIGHT
  86. This program is free software; you can redistribute
  87. it and/or modify it under the same terms as Perl itself.
  88. The full text of the license can be found in the
  89. LICENSE file included with this module.
  90. =head1 SEE ALSO
  91. perl(1), SDL(2).
  92. =cut