OK, I'm just puzzled here. Here is a bigger chunk of code, perhaps I am doing something wrong, and not noticing it? I have the gAidan.WalkingDstRect[].x = gAidan.X_Pos,
same for the Y coordinate rectangle box as well. I've left the width and height of it by 400x400. So it looks like this
gAidan.WalkingDstRect[0].x = gAidan.X_Pos;
gAidan.WalkingDstRect[0].y = gAidan.Y_Pos;
gAidan.WalkingDstRect[0].w = 400;
gAidan.WalkingDstRect[0].h = 400;
I've tried a lot of different things, but for whatever reason, it just won't move. It stays in place while the animation plays.
void RunGame()
{
while(GameRunning)
{
CurrentTime = SDL_GetTicks();
DeltaTime = (float)(CurrentTime - LastTime) / MAX_TICKS;
LastTime = CurrentTime;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
GameRunning = false;
}
if(event.type == SDL_KEYDOWN && event.key.repeat == 0)
{
if(event.key.keysym.sym == SDLK_ESCAPE)
{
GameRunning = false;
}
if(event.key.keysym.sym == SDLK_LEFT)
{
gAidan.Action = gAidan.WALKING;
gAidan.X_Pos -= gAidan.X_Vel * DeltaTime;
}
else if(event.key.keysym.sym == SDLK_RIGHT)
{
gAidan.Action = gAidan.WALKING;
gAidan.X_Pos += gAidan.X_Vel * DeltaTime;
}
if(event.key.keysym.sym == SDLK_UP)
{
gAidan.Action = gAidan.JUMP_A;
}
else if(event.key.keysym.sym == SDLK_DOWN)
{
gAidan.Action = gAidan.CROUCH;
}
}
if(event.type == SDL_KEYUP && event.key.repeat == 0)
{
if(event.key.keysym.sym == SDLK_LEFT)
{
gAidan.X_Vel = 0.0f;
gAidan.Action = gAidan.STANDING;
}
else if(event.key.keysym.sym == SDLK_RIGHT)
{
gAidan.X_Vel = 0.0f;
gAidan.Action = gAidan.STANDING;
}
}
}
Update();
Render();
}
}
void Update()
{
gAidan.WalkingDstRect[gAidan.CurrentFrame].x = (int)gAidan.X_Pos;
}
void Render()
{
SDL_RenderClear(MainRend);
SDL_RenderCopy(MainRend,BackdropTex,NULL,&BackdropRect);
if(gAidan.Action == gAidan.STANDING)
{
SDL_RenderCopy(MainRend,gAidan.StandTex[gAidan.CurrentFrame],NULL,&gAidan.StandDstRect[gAidan.CurrentFrame]);
gAidan.CurrentFrame++;
gAidan.CurrentFrame = SDL_GetTicks() / 100 % 5;
}
if(gAidan.Action == gAidan.WALKING)
{
SDL_RenderCopy(MainRend,gAidan.WalkingTex[gAidan.CurrentFrame], NULL, &gAidan.WalkingDstRect[gAidan.CurrentFrame]);
gAidan.CurrentFrame++;
gAidan.CurrentFrame = SDL_GetTicks() / 100 % 5;
}
SDL_RenderPresent(MainRend);
}