updated docs
[sdlgit/SDL-Site.git] / pages / SDLx-LayerManager.html-inc
CommitLineData
285d0cd2 1<div class="pod">
2<!-- INDEX START -->
3<h3 id="TOP">Index</h3>
4
5<ul><li><a href="#NAME">NAME</a></li>
6<li><a href="#CATEGORY">CATEGORY </a></li>
7<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
8<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
9<li><a href="#METHODS">METHODS</a>
10<ul><li><a href="#new">new</a></li>
11<li><a href="#add">add</a></li>
12<li><a href="#layers">layers</a></li>
13<li><a href="#layer">layer</a></li>
14<li><a href="#length">length</a></li>
15<li><a href="#blit">blit</a></li>
16<li><a href="#by_position">by_position</a></li>
17<li><a href="#ahead">ahead</a></li>
18<li><a href="#behind">behind</a></li>
19<li><a href="#attach">attach</a></li>
20<li><a href="#detach_xy">detach_xy</a></li>
21<li><a href="#detach_back">detach_back</a></li>
22<li><a href="#foreground">foreground</a></li>
23</ul>
24</li>
25<li><a href="#BUGS">BUGS</a></li>
26<li><a href="#SUPPORT">SUPPORT</a></li>
d5943b68 27<li><a href="#AUTHORS">AUTHORS</a></li>
285d0cd2 28<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
29<li><a href="#SEE_ALSO">SEE ALSO</a>
30</li>
31</ul><hr />
32<!-- INDEX END -->
33
34<h1 id="NAME">NAME</h1><p><a href="#TOP" class="toplink">Top</a></p>
35<div id="NAME_CONTENT">
36<p>SDLx::LayerManager - Extension for managing layers in a 2D world</p>
37
38</div>
39<h1 id="CATEGORY">CATEGORY </h1><p><a href="#TOP" class="toplink">Top</a></p>
40<div id="CATEGORY_CONTENT">
41<p>Extension</p>
42
43</div>
44<h1 id="SYNOPSIS">SYNOPSIS</h1><p><a href="#TOP" class="toplink">Top</a></p>
45<div id="SYNOPSIS_CONTENT">
46<pre> use SDLx::Layer;
47 use SDLx::LayerManager;
48
49 use SDL::Image;
50 use SDL::Surface;
51 use SDL::Video;
52
53 # creating layers
54 my $layer1 = SDLx::Layer-&gt;new( SDL::Image::load('image1.png'), {userdata =&gt; '7'} );
55 my $layer2 = SDLx::Layer-&gt;new( SDL::Image::load('image2.png'), 100, 200, {userdata =&gt; '42'} );
56
57 # creating the manager that holds the layers
58 my $layermanager = SDLx::LayerManager-&gt;new();
59 $layermanager-&gt;add( $layer1 );
60 $layermanager-&gt;add( $layer2 );
61
62 my $display = # create your video surface here
63
64 $layermanager-&gt;blit( $display );
65
66 # accessing the layer at point(x,y)
67 print( $layermanager-&gt;by_position( 150, 200 )-&gt;data-&gt;{userdata} ); # should print '42'
68
69</pre>
70
71</div>
72<h1 id="DESCRIPTION">DESCRIPTION</h1><p><a href="#TOP" class="toplink">Top</a></p>
73<div id="DESCRIPTION_CONTENT">
d5943b68 74<p>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.</p>
75<p>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.</p>
76<p>You will even be able to attach one or more layers to the mouse, e.g. for simulation some drag&amp;drop functionality.</p>
285d0cd2 77
78</div>
79<h1 id="METHODS">METHODS</h1><p><a href="#TOP" class="toplink">Top</a></p>
80<div id="METHODS_CONTENT">
81
82</div>
83<h2 id="new">new</h2>
84<div id="new_CONTENT">
d5943b68 85<pre> my $layermanager = SDLx::LayerManager-&gt;new();
86
87</pre>
88<p>This creates your layermanager object. It doesn't take any parameters.</p>
285d0cd2 89
90</div>
91<h2 id="add">add</h2>
92<div id="add_CONTENT">
d5943b68 93<pre> $layermanager-&gt;add( $layer );
94 $layermanager-&gt;add( SDLx::Layer-&gt;new( $surface, $x, $y, $options ) );
95
96</pre>
97<p>Call <code>add</code> to push an SDLx::Layer object to the layermanager.</p>
285d0cd2 98
99</div>
100<h2 id="layers">layers</h2>
101<div id="layers_CONTENT">
d5943b68 102<pre> my @layers = @{ $layermanager-&gt;layers };
103 my $first_layer = $layermanager-&gt;layers-&gt;[0];
104
105</pre>
106<p>The method <code>layers</code> returns all layers that were added before.</p>
285d0cd2 107
108</div>
109<h2 id="layer">layer</h2>
110<div id="layer_CONTENT">
d5943b68 111<pre> my $layer = $layermanager-&gt;layer( $index );
112
113</pre>
114<p>To obtain only one layer at index <code>$index</code> use this function. <code>$index</code> ranges from <code>0</code> to <code>lenght - 1</code>.</p>
285d0cd2 115
116</div>
117<h2 id="length">length</h2>
118<div id="length_CONTENT">
d5943b68 119<pre> my $length = $layermanager-&gt;length();
120
121</pre>
122<p>This method returns the count of the added layers.</p>
285d0cd2 123
124</div>
125<h2 id="blit">blit</h2>
126<div id="blit_CONTENT">
d5943b68 127<pre> $layermanager-&gt;blit( $surface );
128
129</pre>
130<p>This method blits all layers to the surface (e.g. your video surface).</p>
285d0cd2 131
132</div>
133<h2 id="by_position">by_position</h2>
134<div id="by_position_CONTENT">
135<pre> my $layer = $layermanager-&gt;by_position( $x, $y );
136
137</pre>
d5943b68 138<p><code>by_position</code> returns the <code>SDLx::Layer</code> object at point <code>$x $y</code>, which is not fully transparent at this pixel.</p>
285d0cd2 139
140</div>
141<h2 id="ahead">ahead</h2>
142<div id="ahead_CONTENT">
d5943b68 143<pre> my @layers = @{ $layermanager-&gt;ahead( $index ) };
144
145</pre>
146<p>This method returns all layers that are ahead of the given layer indicated by <code>$index</code>.
147Ahead means that a layer has a higher z-index and is blitted over the given layer.</p>
148<p><strong>Note</strong>: This method doesn't check for transparency. This will change in future versions.</p>
285d0cd2 149
150</div>
151<h2 id="behind">behind</h2>
152<div id="behind_CONTENT">
d5943b68 153<pre> my @layers = @{ $layermanager-&gt;behind( $index ) };
154
155</pre>
156<p>This method returns all layers that are behind of the given layer indicated by <code>$index</code>.
157Behind means that a layer has a lower z-index and is blitted before the given layer.</p>
158<p><strong>Note</strong>: This method doesn't check for transparency. This will change in future versions.</p>
285d0cd2 159
160</div>
161<h2 id="attach">attach</h2>
162<div id="attach_CONTENT">
163
164</div>
165<h2 id="detach_xy">detach_xy</h2>
166<div id="detach_xy_CONTENT">
167
168</div>
169<h2 id="detach_back">detach_back</h2>
170<div id="detach_back_CONTENT">
171
172</div>
173<h2 id="foreground">foreground</h2>
174<div id="foreground_CONTENT">
175
176</div>
177<h1 id="BUGS">BUGS</h1><p><a href="#TOP" class="toplink">Top</a></p>
178<div id="BUGS_CONTENT">
179<p>Report at sdlperl.ath.cx</p>
180
181</div>
182<h1 id="SUPPORT">SUPPORT</h1><p><a href="#TOP" class="toplink">Top</a></p>
183<div id="SUPPORT_CONTENT">
184<p>#sdl irc.perl.org</p>
185
186</div>
d5943b68 187<h1 id="AUTHORS">AUTHORS</h1><p><a href="#TOP" class="toplink">Top</a></p>
188<div id="AUTHORS_CONTENT">
189<p>See <b>AUTHORS</b> in <cite>SDL</cite>.</p>
285d0cd2 190
191</div>
192<h1 id="COPYRIGHT">COPYRIGHT</h1><p><a href="#TOP" class="toplink">Top</a></p>
193<div id="COPYRIGHT_CONTENT">
194<p>This program is free software; you can redistribute
195it and/or modify it under the same terms as Perl itself.</p>
196<p>The full text of the license can be found in the
197LICENSE file included with this module.</p>
198
199
200
201
202
203</div>
204<h1 id="SEE_ALSO">SEE ALSO</h1><p><a href="#TOP" class="toplink">Top</a></p>
205<div id="SEE_ALSO_CONTENT">
206<p>perl(1), SDL(2).</p>
207
208</div>
209</div>