Hello, it's me again,
at first: Sorry for my bad English, I usually speak German so please answer in "Simple English" if it's possible
Second: I began SFML yesterday so... yeah I'm a beginner
Here I show you a code of a little program from me:
#include <iostream>
#include <SFML\Graphics.hpp>
int main()
{
sf::RenderWindow mMainWindow(sf::VideoMode(800,600,32),"Test",sf::Style::Titlebar);
sf::Event mMainEvent;
sf::Image car;
car.loadFromFile("car.png");
car.createMaskFromColor(sf::Color::White);
sf::Texture tCar;
tCar.loadFromImage(car);
sf::Sprite sCar(tCar);
while(mMainWindow.isOpen())
{
while(mMainWindow.pollEvent(mMainEvent))
{
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
mMainWindow.close();
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
sCar.move(1,0);
}
mMainWindow.clear();
mMainWindow.draw(sCar);
mMainWindow.display();
}
system("pause");
}
I've got a sprite and if I press the Right-Key it moves to the right 1 pixel every frame. Nothing special.
But now I want that when I pressed the Key e.g. 0.5 seconds, my Sprite moves faster.
sCar.move(3,0);
for example...
So I want something like an acceleration for the sprite. I tried it with
sf::Clock timer;
but if I write that out from the "Keypress-Loop" the timer works always and if I write it in the loop the timer reset every frame.
Is there any solution for that problem or am I just a little bit dumb?
Please don't be too strict because of my English and my knowledge about SFML.
Thanks,
5gum
[edit]If I've got big missktakes in English grammar, please tell that
[/edit]