Sprite class

I’m sure there are already tons of sprite-classes out there. This is however my own interpretation of a Sprite-class.
It has support for animations, pixel-perfect collissions and some other random stuff :wink:

The class can be found here: http://pastebin.com/mTGx37EJ

I have to say, this is a pretty badass and fully-featured sprite class. Looks really good. I was going to harp on your pixel-perfect collision check but I was mistaken and it’s actually very good (I didn’t see it first that width and height were being set from the smallest of the two sprites).

Looks tried and true. What about the various classes this references, like a Logger and PixelGrabber?


import java.awt.image.PixelGrabber;
import java.util.logging.Logger;

Thanks. I know that width and height stuff in that method may be a bit unclear, maybe I’ve should have cleaned it up a bit before releasing it? :wink:
Also, Logger and PixelGrabber (as well as all other imported classes) are part of the JDK (as Riven pointed out) :slight_smile:

perhaps an idea for a small optimization; in my ‘pixel perfect collision detection’ when I create a sprite or bob frame I create an array of booleans by inspecting the pixels. I do that only once at game startup. Then when doing the collision detections, I simply check the pre-generated boolean arrays if two overlapping pixels both hold the value true. Call it a collision mask if you will. These arrays only use up bytes, it won’t even make a small dent on the memory footprint of the game.

Of course that does require a little calculating to figure out which regions of the arrays are actually overlapping, but you are doing something similar when you are copying the pixels over to the arrays you use to do the comparison.

Hey, that’s not a bad idea. Going to build a stress test and check which method is best, thanks :slight_smile:

You can optimise that further by using arrays of wider types and bitwise and - just need to be very careful with the boundaries.

Hi Captain (my Captain :D) Awsome
I just came across your Sprite class and I thought to myself to give it a try.
I actually don’t quite understand all your public methods, though. Do I get it right that an Image is used having tyles of the sprite animation as content?
Are there some nice coding samples how to use your class?

Best wishes

Takidoso