1SDLx::LayerManager(3) User Contributed Perl DocumentationSDLx::LayerManager(3)
2
3
4

NAME

6       SDLx::LayerManager - Extension for managing layers in a 2D world
7

CATEGORY

9       Extension
10

SYNOPSIS

12         use SDLx::Layer;
13         use SDLx::LayerManager;
14
15         use SDL::Image;
16         use SDL::Surface;
17         use SDL::Video;
18
19         # creating layers
20         my $layer1 = SDLx::Layer->new( SDL::Image::load('image1.png'), {userdata => '7'} );
21         my $layer2 = SDLx::Layer->new( SDL::Image::load('image2.png'), 100, 200, {userdata => '42'} );
22
23         # creating the manager that holds the layers
24         my $layermanager = SDLx::LayerManager->new();
25         $layermanager->add( $layer1 );
26         $layermanager->add( $layer2 );
27
28         my $display = # create your video surface here
29
30         $layermanager->blit( $display );
31
32         # accessing the layer at point(x,y)
33         print( $layermanager->by_position( 150, 200 )->data->{userdata} ); # should print '42'
34

DESCRIPTION

36       SDLx::LayerManager is a package to handle a bunch of layers. A layer
37       (see SDLx::Layer) is an SDL::Surface, the position of the surface on
38       screen and some additional information.
39
40       The layermanager gives you the opportunity to obtain the layer at a
41       given point on screen and get the layers that are ahead or behind a
42       layer.
43
44       You will even be able to attach one or more layers to the mouse, e.g.
45       for simulation some drag&drop functionality.
46

METHODS

48   new
49         my $layermanager = SDLx::LayerManager->new();
50
51       This creates your layermanager object. It doesn't take any parameters.
52
53   add
54         $layermanager->add( $layer );
55         $layermanager->add( SDLx::Layer->new( $surface, $x, $y, $options ) );
56
57       Call "add" to push an SDLx::Layer object to the layermanager.
58
59   layers
60         my @layers = @{ $layermanager->layers };
61         my $first_layer = $layermanager->layers->[0];
62
63       The method "layers" returns all layers that were added before.
64
65   layer
66         my $layer = $layermanager->layer( $index );
67
68       To obtain only one layer at index $index use this function. $index
69       ranges from 0 to "length - 1".
70
71   length
72         my $length = $layermanager->length();
73
74       This method returns the count of the added layers.
75
76   blit
77         $layermanager->blit( $surface );
78
79       This method blits all layers to the surface (e.g. your video surface).
80
81   by_position
82         my $layer = $layermanager->by_position( $x, $y );
83
84       "by_position" returns the "SDLx::Layer" object at point "$x $y", which
85       is not fully transparent at this pixel.
86
87   ahead
88         my @layers = @{ $layermanager->ahead( $index ) };
89
90       This method returns all layers that are ahead of the given layer
91       indicated by $index.  Ahead means that a layer has a higher z-index and
92       is blitted over the given layer.
93
94       Note: This method doesn't check for transparency. This will change in
95       future versions.
96
97   behind
98         my @layers = @{ $layermanager->behind( $index ) };
99
100       This method returns all layers that are behind of the given layer
101       indicated by $index.  Behind means that a layer has a lower z-index and
102       is blitted before the given layer.
103
104       Note: This method doesn't check for transparency. This will change in
105       future versions.
106
107   attach
108         $layermanager->attach( $layer,  $x, $y );
109         $layermanager->attach( @layers, $x, $y );
110
111       This function makes the given layer(s) sticky to the mouse. If you move
112       the mouse the layer(s) will follow.  The layermanager blits these
113       layers at last, so they will appear on top of all layers.
114
115       $x and $y should be set to the coords of the mouse, e.g. the coords of
116       the mouse click.  If you omit $x and $y the layermanager obtains them
117       via SDL::Events::get_mouse_state.
118
119       Note: The z-index is not changed for the given layers.
120
121   detach_xy
122         $layermanager->detach_xy( $x, $y );
123
124       "detach_xy" detaches the previously attached layers to the given
125       coords. The upper left corner of the backmost layer will be at $x and
126       $y.  The other layers are positioned relative to the backmost layer
127       just like before.
128
129   detach_back
130         $layermanager->detach_back( );
131
132       "detach_back" detaches the previously attached layers back to the
133       position where they were attached.
134
135   foreground
136         $layermanager->foreground( $layer );
137         $layermanager->foreground( @layers );
138
139       This method moves the given layer(s) to the foreground so that they are
140       blitted on top of the other layers.
141

BUGS

143       Report at sdlperl.ath.cx
144

SUPPORT

146       #sdl irc.perl.org
147

AUTHORS

149       See "AUTHORS" in SDL.
150
152       This program is free software; you can redistribute it and/or modify it
153       under the same terms as Perl itself.
154
155       The full text of the license can be found in the LICENSE file included
156       with this module.
157

SEE ALSO

159       perl(1), SDL(2).
160
161
162
163perl v5.34.0                      2022-01-21             SDLx::LayerManager(3)
Impressum