Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Sprite Class

Sign in to follow this  


[journal dump]

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;
switch (hero.state)
case HeroState.Walking:
if (gamepad.button[PS2GamepadButtons.X])
hero.state = HeroState.SwingingSword;
hero.animation = animations[(int)HeroAnimation.SwingingSword];
// should i be doing the animation selection from the state setting?

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!