1
System / Problems with sf::Thread
« on: January 19, 2010, 08:12:28 pm »
Thanks a lot, guys! The animation works great now!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include <SFML/Graphics.hpp>
#include "AniSprite.h"
using namespace std;
int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600), "Test");
sf::Image Image;
if(!Image.LoadFromFile("character.png"))
{
return EXIT_FAILURE;
}
AniSprite Sprite(Image, 47, 64);
Sprite.SetLoopSpeed(10);
Sprite.SetPosition(0, 400);
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))
{
Sprite.Play(12, 0);
Sprite.Move(-100 * ElapsedTime, 0);
Direction = 0;
}
else if(App.GetInput().IsKeyDown(sf::Key::Right))
{
Sprite.Play(4, 8);
Sprite.Move(100 * ElapsedTime, 0);
Direction = 1;
}
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;
}
#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: invalid use of void expression
void Left(AniSprite Sprite(const sf::Image& Img, int frameW, int frameH))