pods::...anager(3pm)

πŸ’… NAME πŸ’…

SDLx::LayerManager β€” the extension that handles all your layers in a 2D world, bestie ✨

πŸŽ€ CATEGORY πŸŽ€

Extension


✨ SYNOPSIS ✨

okay so here's the whole vibe, literally copy-paste ready:

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('image1.png'), {userdata => '7'} );
my $layer2 = SDLx::Layer->new( SDL::Image::load('image2.png'), 100, 200, {userdata => '42'} );

# 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 '42'

πŸ¦‹ DESCRIPTION πŸ¦‹

So SDLx::LayerManager is this package that handles a whole bunch of layers for you. And a layer (peep SDLx::Layer) is literally an SDL::Surface, plus where that surface sits on screen, plus some extra little info about it. 🫢

The layermanager lets you grab the layer sitting at any given point on screen, and also get all the layers that are ahead of or behind some layer. Super handy, no cap.

You can even attach one or more layers to the mouse β€” like, say you're simulating some drag&drop functionality. Obsessed. πŸ–±οΈβœ¨


🌸 METHODS 🌸

⭐ new

my $layermanager = SDLx::LayerManager->new();

This is what creates your layermanager object. It takes no parameters. That's it, that's the whole thing. πŸ’–

⭐ add

$layermanager->add( $layer );
$layermanager->add( SDLx::Layer->new( $surface, $x, $y, $options ) );

Call add to push an SDLx::Layer object into the layermanager. Stack 'em up, queen. πŸ‘‘

⭐ layers

my @layers = @{ $layermanager->layers };
my $first_layer = $layermanager->layers->[0];

The layers method hands back all the layers that were added before. All of them. The whole squad. πŸ«‚

⭐ layer

my $layer = $layermanager->layer( $index );

Just want one layer at index $index? Use this function. $index ranges from 0 to "length - 1". No off-by-one shenanigans, ok? πŸ’€

⭐ length

my $length = $layermanager->length();

Returns the count of the added layers. Simple. Iconic. πŸŽ€

⭐ blit

$layermanager->blit( $surface );

This method blits all the layers onto the surface (like, your video surface). Everything onto the screen at once, slay. πŸ–ΌοΈ

⭐ by_position

my $layer = $layermanager->by_position( $x, $y );

by_position returns the SDLx::Layer object at the point "$x $y" β€” the one that is not fully transparent at that pixel. Like, the one you can actually see. πŸ‘€βœ¨

⭐ ahead

my @layers = @{ $layermanager->ahead( $index ) };

Returns all layers that are ahead of the layer at $index. "Ahead" meaning the layer has a higher z-index and gets blitted over the given layer. Front-row seats only. πŸ”₯

Note: this method doesn't check for transparency. That's gonna change in future versions, fr fr.

⭐ behind

my @layers = @{ $layermanager->behind( $index ) };

Returns all layers that are behind the layer at $index. "Behind" meaning the layer has a lower z-index and gets blitted before the given layer. Background besties. 🌈

Note: this method doesn't check for transparency. That's gonna change in future versions too, iykyk.

⭐ attach

$layermanager->attach( $layer,  $x, $y );
$layermanager->attach( @layers, $x, $y );

This function makes the given layer(s) sticky to the mouse β€” move the mouse and the layer(s) follow it. πŸ–±οΈπŸ’– The layermanager blits these layers last, so they show up on top of every other layer. Main character energy, honestly.

$x and $y should be set to the coords of the mouse, e.g. the coords of the mouse click. If you omit $x and $y, the layermanager gets them via SDL::Events::get_mouse_state. Convenient much?

Note: the z-index is not changed for the given layers. Just so we're clear. πŸ™ˆ

⭐ detach_xy

$layermanager->detach_xy( $x, $y );

detach_xy detaches the previously attached layers to the given coords. The upper left corner of the backmost layer lands at $x and $y, and the other layers are positioned relative to the backmost layer just like before. Drop 'em where you want. πŸ’…

⭐ detach_back

$layermanager->detach_back( );

detach_back detaches the previously attached layers back to the position where they were attached. Home sweet home. 🏠✨

⭐ foreground

$layermanager->foreground( $layer );
$layermanager->foreground( @layers );

Moves the given layer(s) to the foreground so they get blitted on top of all the other layers. Put yourself first, babe. πŸ‘‘πŸ”₯


πŸ’€ BUGS πŸ’€

Report at sdlperl.ath.cx β€” pls do, we wanna know πŸ™

🫢 SUPPORT 🫢

#sdl on irc.perl.org β€” come through, the chat is cute ✨

🧚 AUTHORS 🧚

See "AUTHORS" in SDL.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

🌟 SEE ALSO 🌟

perl(1), SDL(2).


aaaand that's the whole page, bestie πŸŽ€πŸ’œ this was pods::...anager(3pm) from the User Contributed Perl Documentation, churned out by perl v5.42.3 on 2026-08-19 β€” go forth and layer things, mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from