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

The Greatest screenshot evar!

Sign in to follow this  


Ok, so maybe it does look like an astronaut standing on a hill of chocolate chip cookies[grin]

So yeah, this is my new game project. This screenshot doesn't show off the coolest part of the game yet, animation. That's right, the player sprite is now almost completely animated (except for a jumping frame).

I did come across an interesting bug when writing the animation code, though.

See, to animate my player character, I first created a multi-dimensional array of bitmaps to hold the sprites:

SDL_Surface *player_sprite[2][MAX_FRAME];

MAX_FRAME = 3, by the way.

The first dimension holds the sprites for each direction the player might be facing, which for this game is only right and left. The second dimension holds the max amount of sprite frames in the animation.

Now there was my animation code:

if(m_FrameCount >= m_FrameDelay)
if(m_CurFrame >= MAX_FRAME)
m_CurFrame = 0;

m_FrameCount = 0;

When I ran the program the animation would spin when the player ran right and flicker when it ran left. I thought this was really odd, and it took me quite awhile to find the problem.

Turns out I was trying to access an index pass the bounds of the array. I quickly fixed the problem and now it looks great. However, I would've expected a bug like this to crash the program with an access violation, but it didn't even crash it in the debugger. Does VC++ perform some sort of bounds checking or something like that? that is the only thing I can think of.

Also, does anyone know how to make a SDL program wait for V-Sync? I'm trying to make the scrolling on the game smoother.

Anyways, I'll keep working at it, but it is coming along very nicely so far.
Sign in to follow this  


Recommended Comments

Might I suggest using a more object-oriented approach to sprite animation?

For example, firstly you could separate a sprite from it's animations. Hence, you would have an animation class and a sprite class, the latter of which will contain a list (use SC++L!) of the former (perhaps stored in a std::map so each may be associated with a descriptive name rather than a non-descriptive integer).

Secondly, an animation might consist of a list of frames. A frame, furthermore, might have properties such as image handle (or pointer, or whatever) and display time (this way you can make certain frames display longer for more realistic animations).

Anyway, other than these minor suggestions, it's looking good!

Share this comment

Link to comment
I don't think Visual Studio is doing any bounds checking for you. I think you're probably just reading the variable you declared after the array.

Crashes mostly happen when a process tries to access memory that it doesn't have rights to.

Share this comment

Link to comment
Well, you can read any point in memory, as long as it is within your access block. Generally you will get garbage, but it is only when you try to access memory outside your allocated block (as in, allocated by the OS for you application to run in) will you break things.

C++ and C will go wherever you want. Absolutely no bounds checking or anything like that. You can even set a pointer to an integer value that is read in by the user and try to read the data at that point in memory.

Whether that is a "feature" or a "bug," I will let you decide.

Share this comment

Link to comment

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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!