Hi!
My name is Marcus and I've just started learning SFML. I've recently run in to a small problem that needs to be solved. I'm using AniSprite (
http://www.sfml-dev.org/wiki/en/sources/anisprite) to do a little program with an animated character that can move around a bit. However it's not the graphics part that I have a problem with. When a specified key is pressed I want him to move in a direction and do the animation at the same time. Therefore I thought I could use the sf::Thread-function, but (sadly) it's not working like I want it to work.
Here's the code for
main.cpp:
#include <SFML/Graphics.hpp>
#include "AniSprite.h"
using namespace std;
void Left(AniSprite Sprite)
{
Sprite.Play(4, 8);
Sprite.Update();
}
void Right(AniSprite Sprite)
{
Sprite.Play(12, 0);
Sprite.Update();
}
int main()
{
sf::RenderWindow App(sf::VideoMode(1440, 900), "Test");
sf::Image Image;
if(!Image.LoadFromFile("character.png"))
{
return EXIT_FAILURE;
}
AniSprite Sprite(Image, 47, 64);
Sprite.SetLoopSpeed(10);
Sprite.SetPosition(0, 400);
[b]sf::Thread Thread1(Left(Sprite));[/b]
[b]sf::Thread Thread2(Right(Sprite));[/b]
int Direction = 1;
while(App.IsOpened())
{
sf::Event Event;
while(App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
{
App.Close();
}
}
float ElapsedTime = App.GetFrameTime();
if (App.GetInput().IsKeyDown(sf::Key::Left))
{
Thread1.Launch();
Sprite.Move(-100 * ElapsedTime, 0);
Direction = 1;
}
else if(App.GetInput().IsKeyDown(sf::Key::Right))
{
Thread2.Launch();
Sprite.Move(100 * ElapsedTime, 0);
Direction = 0;
}
else if(Direction == 1)
{
Sprite.Play(4, 5);
}
else
{
Sprite.Play(12, 13);
}
App.Clear();
Sprite.Update();
App.Draw(Sprite);
App.Display();
}
return EXIT_SUCCESS;
}
Error code (line 32 and 33):
error: invalid use of void expression
I've tried different parameters in the
Left- and
Right-functions like:
void Left(AniSprite Sprite(const sf::Image& Img, int frameW, int frameH))
But that'll just end me up with more error codes.
I'll appreciate all help I can get.