i've been thinking a bit about sprite classes lately and i figure its time to sit down and figure out what i want out of a sprite class and how i could go about doing it.
for one thing i'm going to be needing sprites that are going to animate. thats important. not much more to be said about this yet.
another thing i'm going to need out of my sprites is that they're going to need to face in multiple directions for each animation. i'd like to tell the sprite what angle its facing in, in 360' (or 2pi) -based float/double. when i change the facing direction, i want the sprite to know which of the animations to use.
still another is that i'm going to want to have sprite animations with focal points so that i'm not drawing every frame from the upper left or bottom center, i've got a point for every frame that i'm going to use as an anchor. this saves me alot of trouble when i'm trying to do something like the animation for a sword swing. the simplest method would be to have a huge frame full of magenta and a small area where a sword is drawn, to be centered around the player's sprite. i did it before and it worked, but it certainly wasn't very easy to do collision detection with, as that huge picture wasn't very representative of the actual hit area of the sword. no, if i use an anchor point seperated from the picture (relative to the picture), i can draw the sword and have it clip at a much better accuracy than i could before. i'm also saving on memory this way too.
of course, every game works differently and needs different things out of its sprites, and theres no way i could (or would want to) have support for any situation you threw at it. but the above bits are important to me to have in a sprite class, even if i'm not going to use them all. for instance, i might just need a basic sprite that loads up a bitmap - that would default the focal point to the upper-left and all rotation angles would display the single frame, so changing them would amount to nothing.
storing the information in a file and in memory at runtime are two issues to look at too. i *could* just output all the information and bitmaps to a single binary file and give it some god-awful extension. i also could store the bitmaps in a folder (or more awfully, in the exe folder) and have the other info stuffed into an easy-to-read txt file.
if i were to create a single binary file format, i'd most definitely require a visual editor. however, even if the info was in an easy-to-read txt file, i'd still prefer a visual editor. i tried to make one before, as a project to learn c# with. what a disaster that was. god.
anyways, i want to be able to do something like this:
// select sprite direction with the left analog
hero.direction = gamepad.LeftAnalog.direction;
hero.state = HeroState.SwingingSword;
hero.animation = animations[(int)HeroAnimation.SwingingSword];
// should i be doing the animation selection from the state setting?