We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › animation with sprite sheets
Page Index Toggle Pages: 1
animation with sprite sheets (Read 1576 times)
animation with sprite sheets
Feb 2nd, 2010, 2:56pm
 
Hey guys, I need to do some sprite animation. Rather than manually making a bunch of numbered source images that my sprite can animate through in my data folder, I want to have a single sprite sheet for each type of sprite.

When I draw the sprites, I obviously don't want to render the entire sprite sheet. I want to render small pieces of it.

I want to be able to draw a small piece of my sprite sheet each frame by specifying a source rectangle from the sprite sheet. That way, to animate a sprite, I would simply move the rectangle across the sprite sheet that I'm drawing from rather than manually making a series of image files and changing the image I display each frame.

Is this possible?
Re: animation with sprite sheets
Reply #1 - Feb 2nd, 2010, 3:06pm
 
Yes Tongue
Re: animation with sprite sheets
Reply #2 - Feb 2nd, 2010, 3:08pm
 
Roll Eyes  OK... I guess you probably want to know how too

PImage.get() is one option, though apparently a little slower than accessing the PImage pixels array directly.
Re: animation with sprite sheets
Reply #3 - Feb 2nd, 2010, 3:41pm
 
Thanks!! That looks like exactly what I was looking for. That should save me from having to try to line up the perfect rectangle in paint to export images 100 times.
Re: animation with sprite sheets
Reply #4 - Feb 3rd, 2010, 3:07am
 
Although not linked from Processing I have created a sprite library which will do what you want and a lot more.

You might like to try it out
http://www.lagers.org.uk/s4p/index.html

Smiley
Re: animation with sprite sheets
Reply #5 - Feb 3rd, 2010, 10:56am
 
I'm trying to run the examples of your sprites library, but I keep getting a message saying "Note that release 1.0, libraries must be installed in a folder named 'libraries' inside the 'sketchbook' folder."

I went to Documents\Processing\libraries and pasted in the sprites jar file, but I still get that message.

Your library looks interesting but I need to be able to use it first  Tongue

Any help?
Re: animation with sprite sheets
Reply #6 - Feb 3rd, 2010, 11:20am
 
Once you download the zip file you need to unzip it into the Processing/libraries folder.

If you get it right then inside Processing/libraries there will be a folder called
sprites and inside this there will be 4 folders called

examples
library
reference
src


All these are necessary to get the best out of the library, in particular the reference folder contains the library documentation in HTML format (double click on index.html to start it in a browser. The sprites.jar file is in the library folder and there it should stay.

Once this is done you should start/restart Processing and to see the examples select
File | Sketchbook | libraries | sprites | examples and then take your pick.

The lbrary has a lot of features so there is a lot to learn but I think you will find it worth the effort and save you a lot of low level coding.

Hope this helps Smiley
Re: animation with sprite sheets
Reply #7 - Feb 3rd, 2010, 11:35am
 
Yeah I didn't even see that you had an "installation" link on your website. Thanks for the help.

I'll start looking through your examples and other documentation to see how things are done. It does look like it will be worth my while.
Re: animation with sprite sheets
Reply #8 - Feb 3rd, 2010, 12:44pm
 
Is there a more appropriate place than this where I can ask questions about your library? I have a couple of questions.

I have a found a sprite sheet that I'm going to use for my assignment. It's background is that typical hot pink color, so I would like to somehow tell your library "this color pink needs to be transparent". I'd rather not have to make a gray scale alpha mask for every sprite sheet that I download.

Also, a lot of sprite sheets aren't simply rows and columns. A lot have text. For those, will I need to manually make take out the rows and columns that I need?


*edit*
ok I think I answered my own questions. Its probably better to do some manual work with sprite sheets that I download rather than trying to automate it all. I'm just converting my sprite sheets to .PNGs and converting their pink backgrounds to alpha in GIMP. Then I'm just cutting out the rows I need. That's probably easier than trying to code in the coordinates of where I want to start animation frames.

However, I'd still like to know if there's a more appropriate place to ask questions about your sprite library  Wink.
Page Index Toggle Pages: 1