.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "pods::SDLx::Sprite 3pm" .TH pods::SDLx::Sprite 3pm 2024-01-10 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME SDLx::Sprite \- interact with images quick and easily in SDL .SH CATEGORY .IX Header "CATEGORY" Extension .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use SDLx::Sprite; \& \& my $sprite = SDLx::Sprite\->new; \& \& # loads image file into a SDL::Surface and \& # automatically sets a SDL::Rect inside with \& # that image\*(Aqs dimensions. \& $sprite\->load(\*(Aqhero.png\*(Aq); \& \& # set sprite image transparency \& $sprite\->alpha_key( $color ); \& $sprite\->alpha(0.5); \& \& # you can set and check the sprite position anytime \& say $sprite\->x; # rect\->x shortcut accessor \& $sprite\->y(30); # rect\->y shortcut accessor \& \& # read\-only surface dimensions \& $sprite\->w; # width \& $sprite\->h; # height \& \& # you can also fetch the full rect \& # (think destination coordinates for \->draw) \& my $rect = $sprite\->rect; \& \& # you can get the surface object too if you need it \& my $surface = $sprite\->surface; \& \& # rotation() \& \& # if your SDL has gfx, rotation is also straightforward: \& $sprite\->rotation( $degrees ); \& $sprite\->rotation( $degrees, $smooth ); \& \& \& # add() / remove() NOT YET IMPLEMENTED \& # you can also attach other sprites to it \& $sprite\->add( armor => $other_sprite ); \& $sprite\->remove(\*(Aqarmor\*(Aq); \& \& # blits $sprite (and attached sprites) into $screen, \& # in the (x,y) coordinates of the sprite \& $sprite\->draw($screen); \& \& # if you need to clip the original image/surface \& # before drawing it \& $sprite\->clip\->x(10); \& $sprite\->clip\->y(3); \& $sprite\->clip\->w(5); \& $sprite\->clip\->h(5); \& \& # ...or all at once: \& $sprite\->clip($x,$y,$w,$h); \& \& # spawning can include almost all of the above: \& my $sprite = SDLx::Sprite\->new( \& image => \*(Aqhero.png\*(Aq, # or surface => SDL::Surface \& rect => SDL::Rect, # or x => $x, y => $y \& clip => SDL::Rect, \& alpha_key => SDL::Color, # or [$r, $g, $b] \& alpha => 1, \& rotation => 45, # degrees \& ); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" SDLx::Sprite is a SDL::Surface on steroids! It let's you quickly load, setup and interact with images in your SDL application, abstracting all the drudge code and letting you concentrate on your app's logic instead. .PP This module automatically creates and holds SDL::Rect objects for the source and destination surfaces, and provides several surface manipulation options like alpha blending and rotation. .SH "WARNING! VOLATILE CODE AHEAD" .IX Header "WARNING! VOLATILE CODE AHEAD" This is a new module and the API is subject to change without notice. If you care, please join the discussion on the #sdl IRC channel in \&\fIirc.perl.org\fR. All thoughts on further improving the API are welcome. .PP You have been warned :) .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" .ie n .SS "new( %options )" .el .SS "new( \f(CW%options\fP )" .IX Subsection "new( %options )" Creates a new SDLx::Sprite object. No option is mandatory. Available options are: .IP \(bu 4 image => \f(CW$filename\fR .Sp Uses \f(CW$filename\fR as source image for the Sprite's surface. See supported formats in SDL::Image. This option \fBcannot\fR be used together with the 'surface' option (see below). .IP \(bu 4 surface => SDL::Surface .Sp Uses the provided SDL::Surface object as source surface for this sprite, instead of creating one automatically. This option \fBcannot\fR be used together with the 'image' option (see above). .IP \(bu 4 clip => SDL::Rect .Sp Uses the provided SDL::Rect object as clipping rect for the source surface. This means the object will only blit that particular area from the surface. .IP \(bu 4 rect => SDL::Rect .Sp Uses the provided SDL::Rect object as destination coordinates to whatever surface you call \fBdraw()\fR on. You \fBcannot\fR use this option together with 'x' and 'y' (see below) .IP \(bu 4 x => \f(CW$x\fR .Sp Uses \f(CW$x\fR as the x\-axis (left-to-right, 0 being leftmost) positioning of the Sprite into the destination you call \fBdraw()\fR upon. This option \fBcannot\fR be used together with 'rect' (see above). .IP \(bu 4 y => \f(CW$y\fR .Sp Uses \f(CW$y\fR as the y\-axis (top-to-bottom, 0 being topmost) positioning of the Sprite into the destination you call \fBdraw()\fR upon. This option \fBcannot\fR be used together with 'rect' (see above). .IP \(bu 4 draw_xy => \f(CW$surface\fR, \f(CW$x\fR, \f(CW$y\fR .Sp A shortcut to draw at coordinates quickly. Calls x() , y() and \fBdraw()\fR .IP \(bu 4 rotation => \f(CW$degrees\fR, [$smooth] .Sp Uses \f(CW$degrees\fR as the angle to rotate the surface to, in degrees (0..360, remember? :). This option is only available if your compiled SDL library has support for GFX (see Alien::SDL for details). .Sp if \f(CW$smooth\fR is set the sprite is antialiased. This may mess with your alpha_key. .IP \(bu 4 alpha_key => SDL::Color .Sp MUST CALL SDL::Video::get_video_mode prior to this. .Sp Uses the provided SDL::Color object (or an array reference with red, green and blue values) as the color to be turned into transparent (see 'alpha' below). .IP \(bu 4 alpha => \f(CW$percentage\fR or \f(CW$integer\fR .Sp Uses \f(CW$percentage\fR (0 <\-> 1 ) or \f(CW$integer\fR ( 0x01 \- 0xff) as how much transparency to add to the surface. If you use this, it is mandatory that you also provide the alpha_key (see above). .ie n .SS "load( $filename )" .el .SS "load( \f(CW$filename\fP )" .IX Subsection "load( $filename )" Loads the given image file into the object's internal surface. A new surface is \fBalways\fR created, so whatever you had on the previous surface will be lost. Croaks on errors such as no support built for the image or a file reading error (the error message is SDL::get_error and should give more details). .PP Returns the own Sprite object, to allow method chaining. .SS \fBsurface()\fP .IX Subsection "surface()" .SS "surface( SDL::Surface )" .IX Subsection "surface( SDL::Surface )" Returns the object's internal surface, or undef if there is none. .PP If you pass a SDL::Surface to it, it will overwrite the original surface with it, while returning the \fBold\fR (previous) surface. Note that, as such, it will return \f(CW\*(C`undef\*(C'\fR if you use it without having previously loaded either an image or a previous surface. It will Carp::confess if you pass anything that's not an SDL::Surface object (or SDL::Surface subclassed objects). .SS \fBrect()\fP .IX Subsection "rect()" .SS "rect( SDL::Rect )" .IX Subsection "rect( SDL::Rect )" Returns the destination SDL::Rect object used when you call \fBdraw()\fR. .PP If you haven't explicitly set it, it will be a SDL::Rect with the same dimensions as the object's internal surface. If no surface was set yet, it will be an empty SDL::Rect (dimensions 0,0,0,0). .PP If you pass it a SDL::Rect object, it will set \fBrect()\fR to that object before returning, but it will \fBoverwrite\fR any width and height values, as those are read only and set to the size of the underlying surface. .PP If you want to clip the source surface, set \fBclip()\fR instead. .SS \fBclip()\fP .IX Subsection "clip()" .SS "clip( SDL::Rect )" .IX Subsection "clip( SDL::Rect )" Returns the source SDL::Rect object used when you call \fBdraw()\fR. .PP You can use this method to choose only a small subset of the object's internal surface to be used on calls to \fBdraw()\fR. .PP If you haven't explicitly set it, it will be a SDL::Rect with the same dimensions as the object's internal surface. If no surface was set yet, it will be an empty SDL::Rect (dimensions 0,0,0,0). .PP If you pass it a SDL::Rect object, it will set \fBclip()\fR to that object before returning. .SS x() .IX Subsection "x()" .ie n .SS "x( $int )" .el .SS "x( \f(CW$int\fP )" .IX Subsection "x( $int )" Gets/sets the x\-axis (left-to-right, 0 being leftmost) positioning of the Sprite into the destination you call \fBdraw()\fR upon. .PP It is a shortcut to \f(CW\*(C`$sprite\->rect\->x\*(C'\fR. .SS y() .IX Subsection "y()" .ie n .SS "y( $int )" .el .SS "y( \f(CW$int\fP )" .IX Subsection "y( $int )" Gets/sets the y\-axis (top-to-bottom, 0 being topmost) positioning of the Sprite into the destination you call \fBdraw()\fR upon. .PP It is a shortcut to \f(CW\*(C`$sprite\->rect\->y\*(C'\fR. .SS w() .IX Subsection "w()" Returns the Sprite surface's width. This method is read-only. .PP It is a shortcut to \f(CW\*(C`$sprite\->surface\->w\*(C'\fR. .SS h() .IX Subsection "h()" Returns the Sprite surface's height. This method is read-only. .PP It is a shortcut to \f(CW\*(C`$sprite\->surface\->h\*(C'\fR. .SS "draw( SDL::Surface )" .IX Subsection "draw( SDL::Surface )" Draws the Sprite on the provided SDL::Surface object \- usually the screen \- using the blit_surface SDL function, using the source rect from \fBclip()\fR and the destination rect (position) from \fBrect()\fR. .PP Returns the own Sprite object, to allow method chaining. .SH AUTHORS .IX Header "AUTHORS" See "AUTHORS" in SDL. .SH "SEE ALSO" .IX Header "SEE ALSO" SDL::Surface, SDL