.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "pods::SDLx::LayerManager 3pm" .TH pods::SDLx::LayerManager 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SDLx::LayerManager \- Extension for managing layers in a 2D world .SH CATEGORY .IX Header "CATEGORY" Extension .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use SDLx::Layer; \& use SDLx::LayerManager; \& \& use SDL::Image; \& use SDL::Surface; \& use SDL::Video; \& \& # creating layers \& my $layer1 = SDLx::Layer\->new( SDL::Image::load(\*(Aqimage1.png\*(Aq), {userdata => \*(Aq7\*(Aq} ); \& my $layer2 = SDLx::Layer\->new( SDL::Image::load(\*(Aqimage2.png\*(Aq), 100, 200, {userdata => \*(Aq42\*(Aq} ); \& \& # creating the manager that holds the layers \& my $layermanager = SDLx::LayerManager\->new(); \& $layermanager\->add( $layer1 ); \& $layermanager\->add( $layer2 ); \& \& my $display = # create your video surface here \& \& $layermanager\->blit( $display ); \& \& # accessing the layer at point(x,y) \& print( $layermanager\->by_position( 150, 200 )\->data\->{userdata} ); # should print \*(Aq42\*(Aq .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" 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. .PP 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. .PP You will even be able to attach one or more layers to the mouse, e.g. for simulation some drag&drop functionality. .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" .Vb 1 \& my $layermanager = SDLx::LayerManager\->new(); .Ve .PP This creates your layermanager object. It doesn't take any parameters. .SS add .IX Subsection "add" .Vb 2 \& $layermanager\->add( $layer ); \& $layermanager\->add( SDLx::Layer\->new( $surface, $x, $y, $options ) ); .Ve .PP Call \f(CW\*(C`add\*(C'\fR to push an SDLx::Layer object to the layermanager. .SS layers .IX Subsection "layers" .Vb 2 \& my @layers = @{ $layermanager\->layers }; \& my $first_layer = $layermanager\->layers\->[0]; .Ve .PP The method \f(CW\*(C`layers\*(C'\fR returns all layers that were added before. .SS layer .IX Subsection "layer" .Vb 1 \& my $layer = $layermanager\->layer( $index ); .Ve .PP To obtain only one layer at index \f(CW$index\fR use this function. \f(CW$index\fR ranges from \f(CW0\fR to \f(CW\*(C`length \- 1\*(C'\fR. .SS length .IX Subsection "length" .Vb 1 \& my $length = $layermanager\->length(); .Ve .PP This method returns the count of the added layers. .SS blit .IX Subsection "blit" .Vb 1 \& $layermanager\->blit( $surface ); .Ve .PP This method blits all layers to the surface (e.g. your video surface). .SS by_position .IX Subsection "by_position" .Vb 1 \& my $layer = $layermanager\->by_position( $x, $y ); .Ve .PP \&\f(CW\*(C`by_position\*(C'\fR returns the \f(CW\*(C`SDLx::Layer\*(C'\fR object at point \f(CW\*(C`$x $y\*(C'\fR, which is not fully transparent at this pixel. .SS ahead .IX Subsection "ahead" .Vb 1 \& my @layers = @{ $layermanager\->ahead( $index ) }; .Ve .PP This method returns all layers that are ahead of the given layer indicated by \f(CW$index\fR. Ahead means that a layer has a higher z\-index and is blitted over the given layer. .PP \&\fBNote\fR: This method doesn't check for transparency. This will change in future versions. .SS behind .IX Subsection "behind" .Vb 1 \& my @layers = @{ $layermanager\->behind( $index ) }; .Ve .PP This method returns all layers that are behind of the given layer indicated by \f(CW$index\fR. Behind means that a layer has a lower z\-index and is blitted before the given layer. .PP \&\fBNote\fR: This method doesn't check for transparency. This will change in future versions. .SS attach .IX Subsection "attach" .Vb 2 \& $layermanager\->attach( $layer, $x, $y ); \& $layermanager\->attach( @layers, $x, $y ); .Ve .PP This function makes the given layer(s) sticky to the mouse. If you move the mouse the layer(s) will follow. The layermanager blits these layers at last, so they will appear on top of all layers. .PP \&\f(CW$x\fR and \f(CW$y\fR should be set to the coords of the mouse, e.g. the coords of the mouse click. If you omit \f(CW$x\fR and \f(CW$y\fR the layermanager obtains them via SDL::Events::get_mouse_state. .PP \&\fBNote\fR: The z\-index is not changed for the given layers. .SS detach_xy .IX Subsection "detach_xy" .Vb 1 \& $layermanager\->detach_xy( $x, $y ); .Ve .PP \&\f(CW\*(C`detach_xy\*(C'\fR detaches the previously attached layers to the given coords. The upper left corner of the backmost layer will be at \f(CW$x\fR and \f(CW$y\fR. The other layers are positioned relative to the backmost layer just like before. .SS detach_back .IX Subsection "detach_back" .Vb 1 \& $layermanager\->detach_back( ); .Ve .PP \&\f(CW\*(C`detach_back\*(C'\fR detaches the previously attached layers back to the position where they were attached. .SS foreground .IX Subsection "foreground" .Vb 2 \& $layermanager\->foreground( $layer ); \& $layermanager\->foreground( @layers ); .Ve .PP This method moves the given layer(s) to the foreground so that they are blitted on top of the other layers. .SH BUGS .IX Header "BUGS" Report at sdlperl.ath.cx .SH SUPPORT .IX Header "SUPPORT" #sdl irc.perl.org .SH AUTHORS .IX Header "AUTHORS" See "AUTHORS" in SDL. .SH COPYRIGHT .IX Header "COPYRIGHT" This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the LICENSE file included with this module. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1), \fBSDL\fR\|(2).