I have a couple questions / problems, that I'd love if you guys could help.
a) How would I implement multiple hot keys at once? ex. I can be going left and jumping at the same time without lag / freezing.
b) When moving my sprite, I find that there is a lag before it starts to actually move. How can I fix this?
My code is as follows:
#include <SFML/Graphics.hpp>
int pX,pY,Speed = 6;
sf::Event Event;
sf::Sprite Box;
HWND hwnd;
int main()
{
hwnd = FindWindow("Test",NULL);
ShowWindow(hwnd,SW_HIDE);
sf::RenderWindow fa(sf::VideoMode(800,600,256),"Test");
sf::Image image;
if(!image.LoadFromFile("res/Box1.png"))
return EXIT_FAILURE;
Box.SetImage(image);
pY = fa.GetHeight() - (image.GetHeight());
pX = fa.GetWidth() / 2;
while(fa.IsOpened())
{
Box.SetPosition(pX,pY);
while(fa.GetEvent(Event))
{
if (fa.GetInput().IsKeyDown(sf::Key::Left)) pX -= Speed;
if (fa.GetInput().IsKeyDown(sf::Key::Right)) pX += Speed;
if(Event.Type == sf::Event::Closed)
fa.Close();
if(pX > fa.GetWidth()) pX = 0;
}
sf::Image bg;
if(!bg.LoadFromFile("res/background.png"))
return EXIT_FAILURE;
sf::Sprite BG;
BG.SetImage(bg);
BG.SetPosition(0,0);
fa.Clear();
fa.Draw(BG);
fa.Draw(Box);
fa.Display();
}
return 0;
}
[/code]