Witam!
Otóż mam problem, że gdy wciskam strzałkę w lewo postać zamiast zmiany pozycji tworzy nową w innej pozycji.
Kod:
//libraries
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>
#include <windows.h>
using namespace std;
//variables
SDL_Window* window;
SDL_Surface* screen;
SDL_Event event;
int frame=0;
//classes
class TextureManager
{
public:
int Xpos=0;
int Ypos=0;
SDL_Rect rect;
SDL_Surface* Surface;
TextureManager(const char* path, int x=0, int y=0)
{
Xpos=x;
Ypos=y;
Surface = IMG_Load(path);
}
void Refresh()
{
rect.x=Xpos;
rect.y=Ypos;
SDL_BlitScaled(Surface,NULL,screen,&rect);
SDL_BlitSurface(Surface,NULL,screen,&rect);
}
};
//functions
void GameLoop()
{
while(true)
{
if(frame==0)
{
//loading textures
TextureManager RedBall("graphic/ball.bmp", 70,70);
while(frame==0)
{
//events
while(SDL_PollEvent(&zdarzenie))
{
if(zdarzenie.type==SDL_QUIT)
{
exit(0);
}
}
//controls
if(GetAsyncKeyState(VK_LEFT))
{
RedBall.Xpos=RedBall.Xpos-5;
}
//images
RedBall.Refresh();
//refreshing
SDL_UpdateWindowSurface(window);
SDL_Delay(16.66666666666666666666666);
}
SDL_FreeSurface(RedBall.Surface);
}
}
}
int main(int argc, char* args[])
{
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow("Red ball jump", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,800,600,NULL);
screen=SDL_GetWindowSurface(window);
GameLoop();
return 0;
}
Z góry dziękuję za pomoc!