/lib/pods/SDLx/Layer.pod

http://github.com/PerlGameDev/SDL · Unknown · 187 lines · 104 code · 83 blank · 0 comment · 0 complexity · 8c2744a470e55c08f9c023e915cd4dfd MD5 · raw file

  1. =head1 NAME
  2. SDLx::Layer - Storage object for surface and position information
  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. $layer1->foreground;
  20. printf( "%s\n", $layer1->behind->[0]->data->{userdata} ); # prints 42
  21. =head1 DESCRIPTION
  22. A layer (see SDLx::Layer) is an SDL::Surface, the position of the surface on screen and some additional information, e.g. ingame states.
  23. =head1 METHODS
  24. =head2 new
  25. my $layer = SDLx::Layer->new( $surface );
  26. my $layer = SDLx::Layer->new( $surface, %data );
  27. my $layer = SDLx::Layer->new( $surface, $pos_x, %data );
  28. my $layer = SDLx::Layer->new( $surface, $pos_x, $pos_y, %data );
  29. my $layer = SDLx::Layer->new( $surface, $pos_x, $pos_y, $clip_w, %data );
  30. my $layer = SDLx::Layer->new( $surface, $pos_x, $pos_y, $clip_w, $clip_h, %data );
  31. This constructs the layer object. See how you can omit the position and dimension of the layer. The hash C<%data> is for your use only.
  32. The layer object just pass it through.
  33. =head2 index
  34. my $index = $layer->index;
  35. The method C<index> represents the z-index of this layer within its layermanager.
  36. =head2 x
  37. my $x = $layer->x;
  38. This is a shortcut for $layer->pos->x.
  39. =head2 y
  40. my $y = $layer->y;
  41. This is a shortcut for $layer->pos->y.
  42. =head2 w
  43. my $w = $layer->w;
  44. This is a shortcut for $layer->clip->w.
  45. =head2 h
  46. my $h = $layer->h;
  47. This is a shortcut for $layer->pos->h.
  48. =head2 surface
  49. my $surface = $layer->surface;
  50. my $surface = $layer->surface( $new_surface );
  51. B<Example>:
  52. SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos );
  53. This method let you retrieve the current or set a new surface.
  54. =head2 pos
  55. my $rect = $layer->pos;
  56. The method C<pos> returns an SDL::Rect object. The pos x and y are stored there.
  57. B<Example>:
  58. SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos );
  59. =head2 clip
  60. my $rect = $layer->clip;
  61. The method C<clip> returns an SDL::Rect object. The clip width and height are stored there.
  62. B<Example>:
  63. SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos );
  64. =head2 data
  65. my %data = %{ $layer->data };
  66. my %data = %{ $layer->data( %new_data) };
  67. This method returns the hash C<%data>. You can set C<%data> by passing a hash.
  68. =head2 ahead
  69. my @layers = $layer->ahead;
  70. This method returns all layers that are ahead of the given layer.
  71. Ahead means that a layer has a higher z-index and is blitted over the given layer.
  72. B<Note>: This method doesn't check for transparency. This will change in future versions.
  73. =head2 behind
  74. my @layers = $layer->behind;
  75. This method returns all layers that are behind of the given layer.
  76. Behind means that a layer has a lower z-index and is blitted over the given layer.
  77. B<Note>: This method doesn't check for transparency. This will change in future versions.
  78. =head2 attach
  79. $layer->attach( $x, $y );
  80. This function makes the given layer sticky to the mouse. If you move the mouse the layer will follow.
  81. The layermanager blits this layer at last, so they will appear on top of all layers.
  82. C<$x> and C<$y> should be set to the coords of the mouse, e.g. the coords of the mouse click.
  83. If you omit C<$x> and C<$y> the layer obtains them via SDL::Events::get_mouse_state.
  84. B<Note>: The z-index is not changed for the given layer.
  85. =head2 detach_xy
  86. $layer->detach_xy( $x, $y );
  87. C<detach_xy> detaches the previously attached layer to the given coords. The upper left corner of this layer will be at C<$x> and C<$y>.
  88. =head2 foreground
  89. $layer->foreground;
  90. This method moves the given layer to the foreground so that it is blitted on top of the other layers.
  91. =head1 BUGS
  92. Report at sdlperl.ath.cx
  93. =head1 SUPPORT
  94. #sdl irc.perl.org
  95. =head1 AUTHORS
  96. See L<SDL/AUTHORS>.
  97. =head1 COPYRIGHT
  98. This program is free software; you can redistribute
  99. it and/or modify it under the same terms as Perl itself.
  100. The full text of the license can be found in the
  101. LICENSE file included with this module.
  102. =head1 SEE ALSO
  103. perl(1), SDL(2).
  104. =cut