Index


NAME

Top

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

CATEGORY

Top

Extension

SYNOPSIS

Top

  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

Top

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.

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.

You will even be able to attach one or more layers to the mouse, e.g. for simulation some drag&drop functionality.

METHODS

Top

new

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

This creates your layermanager object. It doesn't take any parameters.

add

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

Call add to push an SDLx::Layer object to the layermanager.

layers

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

The method layers returns all layers that were added before.

layer

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

To obtain only one layer at index $index use this function. $index ranges from 0 to lenght - 1.

length

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

This method returns the count of the added layers.

blit

  $layermanager->blit( $surface );

This method blits all layers to the surface (e.g. your video surface).

by_position

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

by_position returns the SDLx::Layer object at point $x $y, which is not fully transparent at this pixel.

ahead

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

This method returns all layers that are ahead of the given layer indicated by $index. Ahead means that a layer has a higher z-index and is blitted over the given layer.

Note: This method doesn't check for transparency. This will change in future versions.

behind

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

This method returns all layers that are behind of the given layer indicated by $index. Behind means that a layer has a lower z-index and is blitted before the given layer.

Note: This method doesn't check for transparency. This will change in future versions.

attach

detach_xy

detach_back

foreground

BUGS

Top

Report at sdlperl.ath.cx

SUPPORT

Top

#sdl irc.perl.org

AUTHORS

Top

See AUTHORS in SDL.

COPYRIGHT

Top

SEE ALSO

Top

perl(1), SDL(2).