10th anniversary of my Game Sprite Image Fetch lib
### the following code can be used as e.g. a Game Sprite's
### images which can be fetched from its queue-like
### list. You add a sequence of images which is the sprite's
### images for moving, jumping, ...
# Copyright (C) 2012 erana
# This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
# This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTAB
+ILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
# You should have received a copy of the GNU General Public License al
+ong with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
package StateImageLibrary;
use SDL;
use SDL::Video;
use SDL::Surface;
use SDL::Image;
use SDL::Rect;
use SDLx::App;
BEGIN{ unshift(@INC,"../blib/");}
BEGIN{ unshift(@INC,"../blib/lib");}
BEGIN{ unshift(@INC,"../blib/arch");}
sub new {
my $class = shift;
my $self = { $index = 0, @images = undef, };
bless $self, $class;
return $self;
};
sub add {
my ($self, $imagefn) = @_;
my $pngsurface = SDL::Image::load($imagefn);
my $surface = SDLx::Surface->new( surface => $pngsurface);
$self->{images}[$self->index++] = $surface;
};
sub addImage {
add(shift);
};
sub get {
my $self = shift;
if ($self->index >= $#images) {
$self->index = 0;
}
return $self->{image}[$self->index++];
};
1;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.