Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - marcsven

Pages: [1]
1
System / Problems with sf::Thread
« on: January 19, 2010, 08:12:28 pm »
Thanks a lot, guys! The animation works great now! :D

2
System / Problems with sf::Thread
« on: January 19, 2010, 05:06:11 pm »
Look at this code and you'll maybe get my problem:
Code: [Select]
#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;
}

The animation won't update when the user is moving it. :(

3
System / Problems with sf::Thread
« on: January 18, 2010, 08:32:08 pm »
I've tried using Play() and Update() in the main loop, but when I press the key the animation stops. I thought it was because it can't move and update the animation at the same time. :?

4
System / Problems with sf::Thread
« on: January 18, 2010, 06:18:13 pm »
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:
Code: [Select]
#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):
Code: [Select]
error: invalid use of void expression
I've tried different parameters in the Left- and Right-functions like:
Code: [Select]
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. :)

Pages: [1]
anything