1SDLx::Layer(3)        User Contributed Perl Documentation       SDLx::Layer(3)
2
3
4

NAME

6       SDLx::Layer - Storage object for surface and position information
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         $layer1->foreground;
31         printf( "%s\n", $layer1->behind->[0]->data->{userdata} ); # prints 42
32

DESCRIPTION

34       A layer (see SDLx::Layer) is an SDL::Surface, the position of the
35       surface on screen and some additional information, e.g. ingame states.
36

METHODS

38   new
39         my $layer = SDLx::Layer->new( $surface );
40         my $layer = SDLx::Layer->new( $surface,                                   %data );
41         my $layer = SDLx::Layer->new( $surface, $pos_x,                           %data );
42         my $layer = SDLx::Layer->new( $surface, $pos_x, $pos_y,                   %data );
43         my $layer = SDLx::Layer->new( $surface, $pos_x, $pos_y, $clip_w,          %data );
44         my $layer = SDLx::Layer->new( $surface, $pos_x, $pos_y, $clip_w, $clip_h, %data );
45
46       This constructs the layer object. See how you can omit the position and
47       dimension of the layer. The hash %data is for your use only.  The layer
48       object just pass it through.
49
50   index
51         my $index = $layer->index;
52
53       The method "index" represents the z-index of this layer within its
54       layermanager.
55
56   x
57         my $x = $layer->x;
58
59       This is a shortcut for $layer->pos->x.
60
61   y
62         my $y = $layer->y;
63
64       This is a shortcut for $layer->pos->y.
65
66   w
67         my $w = $layer->w;
68
69       This is a shortcut for $layer->clip->w.
70
71   h
72         my $h = $layer->h;
73
74       This is a shortcut for $layer->pos->h.
75
76   surface
77         my $surface = $layer->surface;
78         my $surface = $layer->surface( $new_surface );
79
80       Example:
81
82         SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos );
83
84       This method let you retrieve the current or set a new surface.
85
86   pos
87         my $rect = $layer->pos;
88
89       The method "pos" returns an SDL::Rect object. The pos x and y are
90       stored there.
91
92       Example:
93
94         SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos );
95
96   clip
97         my $rect = $layer->clip;
98
99       The method "clip" returns an SDL::Rect object. The clip width and
100       height are stored there.
101
102       Example:
103
104         SDL::Video::blit_surface( $layer->surface, $layer->clip, $destination_surface, $layer->pos );
105
106   data
107         my %data = %{ $layer->data };
108         my %data = %{ $layer->data( %new_data) };
109
110       This method returns the hash %data. You can set %data by passing a
111       hash.
112
113   ahead
114         my @layers = $layer->ahead;
115
116       This method returns all layers that are ahead of the given layer.
117       Ahead means that a layer has a higher z-index and is blitted over the
118       given layer.
119
120       Note: This method doesn't check for transparency. This will change in
121       future versions.
122
123   behind
124         my @layers = $layer->behind;
125
126       This method returns all layers that are behind of the given layer.
127       Behind means that a layer has a lower z-index and is blitted over the
128       given layer.
129
130       Note: This method doesn't check for transparency. This will change in
131       future versions.
132
133   attach
134         $layer->attach( $x, $y );
135
136       This function makes the given layer sticky to the mouse. If you move
137       the mouse the layer will follow.  The layermanager blits this layer at
138       last, so they will appear on top of all layers.
139
140       $x and $y should be set to the coords of the mouse, e.g. the coords of
141       the mouse click.  If you omit $x and $y the layer obtains them via
142       SDL::Events::get_mouse_state.
143
144       Note: The z-index is not changed for the given layer.
145
146   detach_xy
147         $layer->detach_xy( $x, $y );
148
149       "detach_xy" detaches the previously attached layer to the given coords.
150       The upper left corner of this layer will be at $x and $y.
151
152   foreground
153         $layer->foreground;
154
155       This method moves the given layer to the foreground so that it is
156       blitted on top of the other layers.
157

BUGS

159       Report at sdlperl.ath.cx
160

SUPPORT

162       #sdl irc.perl.org
163

AUTHORS

165       See "AUTHORS" in SDL.
166
168       This program is free software; you can redistribute it and/or modify it
169       under the same terms as Perl itself.
170
171       The full text of the license can be found in the LICENSE file included
172       with this module.
173

SEE ALSO

175       perl(1), SDL(2).
176
177
178
179perl v5.30.1                      2020-01-30                    SDLx::Layer(3)
Impressum