Hello,
Whenever I try to move my character using the keyboard, it crashes after a few second. I'll post the code and where it says the crash is coming from.
gPlayer.XPos = MAX_WIDTH / 2;
gPlayer.YPos = MAX_HEIGHT / 2;
gPlayer.XVel = 0.010f;
gPlayer.YVel = 0.010f;
gPlayer.CurrentFrame = 1;
for(int i = 0; i <= 8; i++)
{
gPlayer.LeftRect[i].x = gPlayer.XPos;
gPlayer.LeftRect[i].y = gPlayer.YPos;
gPlayer.LeftRect[i].w = gPlayer.Width;
gPlayer.LeftRect[i].h = gPlayer.Height;
}
else if(event.key.keysym.sym == SDLK_LEFT)
{
gPlayer.Facing = gPlayer.LEFT;
gPlayer.CurrentState = gPlayer.WALK_LEFT;
}
else if(event.key.keysym.sym == SDLK_LEFT)
{
gPlayer.CurrentState = gPlayer.IDLE;
gPlayer.Facing = gPlayer.LEFT;
gPlayer.XVel = 0.0f;
}
if(gPlayer.CurrentState == gPlayer.WALK_LEFT)
{
gPlayer.LeftRect[gPlayer.CurrentFrame].x -= 3;
}
if(gPlayer.CurrentState == gPlayer.WALK_LEFT)
{
SDL_RenderCopy(GameRend,gPlayer.LeftTex[gPlayer.CurrentFrame],NULL,&gPlayer.LeftRect[gPlayer.CurrentFrame]);
gPlayer.CurrentFrame++; //This is where the debugger points to when it crashes
gPlayer.CurrentFrame = SDL_GetTicks() / 150 % 8;
}
I've only posted bits and pieces of my code. I can post more if it is needed. My problem is it runs fine when first executed, but when I try to move the character, it shows the animation play, then crashes after a couple of seconds. NOTE: There are 8 animations for the character walking.