Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

2D sprite png image library

by erana (Initiate)
on Dec 10, 2012 at 00:40 UTC ( #1008012=CUFP: print w/replies, xml ) Need Help??

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;

Replies are listed 'Best First'.
Re: 2D sprite png image library
by erana (Initiate) on Dec 10, 2012 at 00:49 UTC I just started on them after some Java

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://1008012]
Approved by bitingduck
[marto]: thanks

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2018-06-25 10:02 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.