From: Kartik Thakore Date: Tue, 20 Jul 2010 15:33:56 +0000 (+0000) Subject: Added animated X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=sdlgit%2FSDL-Site.git;a=commitdiff_plain;h=1f1aba66ccca27efdefae3c658bf3e11886a5dd0 Added animated --- diff --git a/pages/SDLx-Sprite-Animated.html-inc b/pages/SDLx-Sprite-Animated.html-inc new file mode 100644 index 0000000..b1bd058 --- /dev/null +++ b/pages/SDLx-Sprite-Animated.html-inc @@ -0,0 +1,337 @@ +
+ +

Index

+ +
+ + +

NAME

Top

+
+

SDLx::Sprite::Animated - create animated SDL sprites easily!

+ +
+

CATEGORY

Top

+
+

Extension

+ +
+

SYNOPSIS

Top

+
+
  use SDLx::Sprite::Animated;
+
+  # simplest possible form, where 'hero.png' is an image containing
+  # fixed-length sprites in sequence. It doesn't matter if they are
+  # placed vertically or horizontally, as long as the the widest
+  # side is a multiple of the (narrowest) other. The widget will
+  # automatically divide it in the proper frames, provided there is
+  # no slack space between each frame.
+
+  my $animation = SDLx::Sprite::Animated->new->load('hero.png');
+
+  # that's it! Defaults are sane enough to DWIM in simple cases,
+  # so you just have to call draw() on the right place. If you
+  # need to setup your animation or have more control over it,
+  # feel free to use the attributes and methods below.
+
+  # these are the most useful methods to use in your game loop
+  # (or wherever you want to manipulate the animation):
+  $animation->next;
+  $animation->previous;
+  $animation->reset;
+
+  $animation->current_frame;   # current frame number
+  $animation->current_loop;    # current loop number
+
+  # you can control positioning just like a regular SDLx::Sprite:
+  $animation->rect
+  $animation->x;
+  $animation->y;
+
+  # just like a regular Sprite, we fetch our source rect from ->clip,
+  # updating it on each call to ->next (or ->previous, or ->reset).
+  # If source rects for your animation are further appart (or less)
+  # than the rect's width and height, you can adjust the animation
+  # x/y offsets:
+  $animation->step_x(15);
+  $animation->step_y(30);
+
+  $animation->draw($screen); # remember to do this! :)
+
+  # we can also call ->next() automatically after each draw():
+  $animation->start;
+  $animation->stop;
+
+  # default is to go to the next frame at each draw(). If this is
+  # too fast for you, change the attribute below:
+  $animation->ticks_per_frame(10);
+
+  # select type of animation loop when it reaches the last frame:
+  $animation->type('circular'); # restarts loop at the beginning
+  $animation->type('reverse');  # goes backwards
+
+  $animation->max_loops(3); 0 or undef for infinite looping
+
+
+
+
+  # as usual, you can setup most of the above during object spawning
+  my $animation = SDLx::Sprite::Animated->new(
+                       image  => 'hero.png',
+                       rect   => SDL::Rect->new(...),
+                       step_x => 20,
+                       step_y => 0,
+                       ...
+                  );
+
+
+
+
+
+ +
+

DESCRIPTION

Top

+
+

An animation is a series of frames that are played in order. Frames are +loaded from an image, usually referred to as a Sprite Sheet or Sprite Strip.

+

This module let's you interact with such strips and create sprite animations +just as easily as you would manipulate a regular SDLx::Sprite object.

+ +
+

WARNING! VOLATILE CODE AHEAD

Top

+
+

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 +irc.perl.org. All thoughts on further improving the API are welcome.

+

You have been warned :)

+ +
+

ATTRIBUTES AND METHODS

Top

+
+

SDLx::Sprite::Animated is a subclass of SDLx::Sprite, inheriting +all its attributes and methods. Please refer to that module's documentation +for information on those.

+

The one difference in behavior is that, while a standard SDLx::Sprite uses +->clip() to select the part of the surface to display, +SDLx::Sprite::Animated treats ->clip() as the initial rect, from +which to start the animation.

+

The following attributes and methods are available:

+ +
+

new

+
+ +
+

new( %options )

+
+

Creates a new SDLx::Sprite::Animated object. No option is mandatory. It +accepts all the options from a regular SDLx::Sprite object plus these:

+
+
* step_x => $integer
+
+

Uses $integer as the number of pixels to move on the x-axis (left-to-right, +0 being no dislocation whatsoever, when the strip goes from top to bottom) +to reach the next frame.

+
+
* step_y => $integer
+
+

Uses $integer as the number of pixels to move on the y-axis (top-to-bottom, +0 being no dislocation whatsoever, when the strip goes from left to right) +to reach the next frame.

+
+
* max_loops => $integer
+
+

Uses $integer as the number of times to loop the animation (when it reaches +the end of the strip).

+
+
* ticks_per_frame => $integer
+
+

Uses $integer to set how many calls to draw() must be issued before we go to +the next frame during autoplay (i.e. between calls to start() and stop()).

+
+
* type => $string
+
+

Uses $string to set the type of animation loop when it reaches the last +frame in the strip. See the type() method below for information on +available looping types.

+
+
+ +
+

step_x()

+
+ +
+

step_x( $integer )

+
+

Uses $integer as the number of pixels to move on the x-axis (left-to-right, +0 being no dislocation whatsoever, when the strip goes from top to bottom) +to reach the next frame.

+

Defaults to the same width as the clip() rect.

+ +
+

step_y()

+
+ +
+

step_y( $integer )

+
+

Uses $integer as the number of pixels to move on the y-axis (top-to-bottom, +0 being no dislocation whatsoever, when the strip goes from left to right) +to reach the next frame.

+

Defaults to the same height as the clip() rect.

+ +
+

max_loops()

+
+ +
+

max_loops( $integer )

+
+

Uses $integer as the number of times to loop the animation (when it reaches +the end of the strip). After that all calls to previous() or next() will be no-ops.

+

Set it to 0 or undef to allow infinite loops. Default is 0 (infinite).

+ +
+

ticks_per_frame()

+
+ +
+

ticks_per_frame( $integer )

+
+

Uses $integer to set how many calls to draw() must be issued before we go to +the next frame during autoplay (i.e. between calls to start() and stop()).

+

Default is just 1 tick per frame, so you might want to change this if it's too fast.

+ +
+

type()

+
+ +
+

type( $string )

+
+

Uses $string to set the type of animation loop when it reaches the last +frame in the strip. Available looping types are:

+
+
* 'circular'
+
+

Restarts loop at the beginning of the strip. If you have 4 frames, the flow +will be 1-2-3-4-1-2-3-4-1-2-3-4-1-2-... up until the number of loops you +set in the max_loops() attribute.

+
+
* 'reverse'
+
+

Loops back and forth on the strip. If you have 4 frames, the flow will be +1-2-3-4-3-2-1-2-3-4-3-2-... up until the number of loops you set in the +max_loops() attribute.

+
+
+

Case is irrelevant for type(), so for example 'Circular', 'CIRCULAR' and +'CiRcUlAr' are all accepted as 'circular'. The return value is guaranteed +to be lowercase.

+

Default value is 'circular'.

+ +
+

next()

+
+

Goes to the next frame in the strip. Calling this method will also reset +the tick counter used by ticks_per_frame().

+

If max_loops() has reached its limit, this will be a no-op.

+

Returns the object, allowing method chaining.

+ +
+

previous()

+
+

Goes to the previous frame in the strip. Calling this method will also reset +the tick counter used by ticks_per_frame().

+

If max_loops() has reached its limit, this will be a no-op.

+

Returns the object, allowing method chaining.

+ +
+

reset()

+
+

Goes to the first frame in the strip, meaning whatever clip is set to.

+

If max_loops() has reached its limit, this will be a no-op.

+

Returns the object, allowing method chaining.

+ +
+

current_frame()

+
+

Returns the current frame number. Note that this is 1-based (first frame +is 1, second is 2, etc).

+ +
+

current_loop()

+
+

Returns the loop counter, i.e. which run number is it at. This is also +1-based (first time is 1, second time is 2, etc). Note that we only +keep track of the counter if max_loops() is set to a finite number. Otherwise, +this will be a no-op.

+ +
+

start()

Top

+
+

After you call this method, the object will issue a call to ->next() +automatically for you every time ->draw() is called +ticks_per_frame() times.

+

If you want to stop autoplay, see stop() below.

+

Default is off (no autoplay).

+ +
+

stop()

Top

+
+

Stops autoplay. After you call this, the object will need you to call +->previous() and ->next() explicitly to change frames.

+

To resume autoplay from wherever you are, use start().

+

If you want to restart autoplay from the initial frame, just do:

+
  $sprite->reset->start;
+
+
+
+
+
+ +
+

AUTHORS

Top

+
+

Jeffrey T. Palmer <jeffrey.t.palmer at gmail.com>

+

Dustin Mays, <dork.fish.wat@gmail.com>

+

Breno G. de Oliveira, <garu at cpan.org>

+

Kartik thakore <kthakore at cpan.org>

+ +
+

SEE ALSO

Top

+ +
\ No newline at end of file diff --git a/pages/documentation.html-inc b/pages/documentation.html-inc index 7293587..4c0d6aa 100644 --- a/pages/documentation.html-inc +++ b/pages/documentation.html-inc @@ -1,2 +1,2 @@
-

Documentation (latest development branch)

Core
thumbSDL- Simple DirectMedia Layer for Perl
thumbSDL::Credits- Authors and contributors of the SDL Perl project
thumbSDL::Deprecated- Log of Deprecated items per release
thumbSDL::Time- An SDL Perl extension for managing timers
Audio
thumbSDL::Audio- SDL Bindings for Audio
Structure
thumbSDL::AudioCVT- Audio Conversion Structure
thumbSDL::AudioSpec- SDL Bindings for structure SDL::AudioSpec
CDROM
thumbSDL::CDROM- SDL Bindings for the CDROM device
Structure
thumbSDL::CD- SDL Bindings for structure SDL_CD
thumbSDL::CDTrack- SDL Bindings for structure SDL_CDTrack
Events
thumbSDL::Events- Bindings to the Events Category in SDL API
Structure
thumbSDL::Event- General event structure
Joystick
thumbSDL::Joystick- SDL Bindings for the Joystick device
Mouse
thumbSDL::Mouse- SDL Bindings for the Mouse device
Structure
thumbSDL::Cursor- Mouse cursor structure
Structure
thumbSDL::Version- SDL Bindings for structure SDL_Version
Video
thumbSDL::Video- Bindings to the video category in SDL API
Structure
thumbSDL::Color- Format independent color description
thumbSDL::Overlay- YUV Video overlay
thumbSDL::Palette- Color palette for 8-bit pixel formats
thumbSDL::PixelFormat- Stores surface format information
thumbSDL::Rect- Defines a rectangular area
thumbSDL::Surface- Graphic surface structure
thumbSDL::VideoInfo- Video Target Information

Cookbook
thumbSDL::Cookbook
thumbSDL::Cookbook::OpenGL- Using SDL with OpenGL
thumbSDL::Cookbook::PDL

Extension
thumbSDLx::App- a SDL perl extension
thumbSDLx::Rect- SDL extension for storing and manipulating rectangular coordinates
thumbSDLx::SFont- Extension making fonts out of images and printing them
thumbSDLx::Sprite- interact with images quick and easily in SDL
thumbSDLx::Surface- Graphic surface matrix extension

GFX
thumbSDL::GFX::Framerate- framerate calculating functions
thumbSDL::GFX::Primitives- basic drawing functions
Structure
thumbSDL::GFX::FPSManager- data structure used by SDL::GFX::Framerate

Image
thumbSDL::Image- Bindings for the SDL_Image library

Mixer
thumbSDL::Mixer- Sound and music functions
thumbSDL::Mixer::Channels- SDL::Mixer channel functions and bindings
thumbSDL::Mixer::Effects- sound effect functions
thumbSDL::Mixer::Groups- Audio channel group functions
thumbSDL::Mixer::Music- functions for music
thumbSDL::Mixer::Samples- functions for loading sound samples
Structure
thumbSDL::Mixer::MixChunk- SDL Bindings for structure SDL_MixChunk
thumbSDL::Mixer::MixMusic- SDL Bindings for structure SDL_MixMusic

Pango
thumbSDL::Pango- Text rendering engine
Structure
thumbSDL::Pango::Context- Context object for SDL::Pango

TODO
thumbSDL::MPEG- a SDL perl extension
thumbSDL::SMPEG- a SDL perl extension
MultiThread
thumbSDL::MultiThread- Bindings to the MultiThread category in SDL API
Structure
thumbSDL::RWOps- SDL Bindings to SDL_RWOPs
GFX
thumbSDL::GFX::BlitFunc- blitting functions
thumbSDL::GFX::ImageFilter- image filtering functions
thumbSDL::GFX::Rotozoom- rotation and zooming functions for surfaces

TTF
thumbSDL::TTF- True Type Font functions (libfreetype)
Structure
thumbSDL::TTF::Font- Font object type for SDL_ttf

Tutorials
thumbSDL::Tutorial- introduction to Perl SDL
thumbSDL::Tutorial::LunarLander- a small tutorial on Perl SDL

UNCATEGORIZED
thumbSDL::Tutorial::Animation
thumbSDLx::Controller- Handles the loops for event, movement and rendering
+

Documentation (latest development branch)

Core
thumbSDL- Simple DirectMedia Layer for Perl
thumbSDL::Credits- Authors and contributors of the SDL Perl project
thumbSDL::Deprecated- Log of Deprecated items per release
thumbSDL::Time- An SDL Perl extension for managing timers
Audio
thumbSDL::Audio- SDL Bindings for Audio
Structure
thumbSDL::AudioCVT- Audio Conversion Structure
thumbSDL::AudioSpec- SDL Bindings for structure SDL::AudioSpec
CDROM
thumbSDL::CDROM- SDL Bindings for the CDROM device
Structure
thumbSDL::CD- SDL Bindings for structure SDL_CD
thumbSDL::CDTrack- SDL Bindings for structure SDL_CDTrack
Events
thumbSDL::Events- Bindings to the Events Category in SDL API
Structure
thumbSDL::Event- General event structure
Joystick
thumbSDL::Joystick- SDL Bindings for the Joystick device
Mouse
thumbSDL::Mouse- SDL Bindings for the Mouse device
Structure
thumbSDL::Cursor- Mouse cursor structure
Structure
thumbSDL::Version- SDL Bindings for structure SDL_Version
Video
thumbSDL::Video- Bindings to the video category in SDL API
Structure
thumbSDL::Color- Format independent color description
thumbSDL::Overlay- YUV Video overlay
thumbSDL::Palette- Color palette for 8-bit pixel formats
thumbSDL::PixelFormat- Stores surface format information
thumbSDL::Rect- Defines a rectangular area
thumbSDL::Surface- Graphic surface structure
thumbSDL::VideoInfo- Video Target Information

Cookbook
thumbSDL::Cookbook
thumbSDL::Cookbook::OpenGL- Using SDL with OpenGL
thumbSDL::Cookbook::PDL

Extension
thumbSDLx::App- a SDL perl extension
thumbSDLx::Rect- SDL extension for storing and manipulating rectangular coordinates
thumbSDLx::SFont- Extension making fonts out of images and printing them
thumbSDLx::Sprite- interact with images quick and easily in SDL
thumbSDLx::Sprite::Animated- create animated SDL sprites easily!
thumbSDLx::Surface- Graphic surface matrix extension

GFX
thumbSDL::GFX::Framerate- framerate calculating functions
thumbSDL::GFX::Primitives- basic drawing functions
Structure
thumbSDL::GFX::FPSManager- data structure used by SDL::GFX::Framerate

Image
thumbSDL::Image- Bindings for the SDL_Image library

Mixer
thumbSDL::Mixer- Sound and music functions
thumbSDL::Mixer::Channels- SDL::Mixer channel functions and bindings
thumbSDL::Mixer::Effects- sound effect functions
thumbSDL::Mixer::Groups- Audio channel group functions
thumbSDL::Mixer::Music- functions for music
thumbSDL::Mixer::Samples- functions for loading sound samples
Structure
thumbSDL::Mixer::MixChunk- SDL Bindings for structure SDL_MixChunk
thumbSDL::Mixer::MixMusic- SDL Bindings for structure SDL_MixMusic

Pango
thumbSDL::Pango- Text rendering engine
Structure
thumbSDL::Pango::Context- Context object for SDL::Pango

TODO
thumbSDL::MPEG- a SDL perl extension
thumbSDL::SMPEG- a SDL perl extension
MultiThread
thumbSDL::MultiThread- Bindings to the MultiThread category in SDL API
Structure
thumbSDL::RWOps- SDL Bindings to SDL_RWOPs
GFX
thumbSDL::GFX::BlitFunc- blitting functions
thumbSDL::GFX::ImageFilter- image filtering functions
thumbSDL::GFX::Rotozoom- rotation and zooming functions for surfaces

TTF
thumbSDL::TTF- True Type Font functions (libfreetype)
Structure
thumbSDL::TTF::Font- Font object type for SDL_ttf

Tutorials
thumbSDL::Tutorial- introduction to Perl SDL
thumbSDL::Tutorial::LunarLander- a small tutorial on Perl SDL

UNCATEGORIZED
thumbSDL::Tutorial::Animation
thumbSDLx::Controller- Handles the loops for event, movement and rendering