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 - ebior123

Pages: [1]
1
Graphics / Re: Animation in thor does not play.
« on: May 16, 2017, 09:33:56 pm »
Thank you! Finally it works. You are the best

2
Graphics / Re: Animation in thor does not play.
« on: May 15, 2017, 10:13:24 pm »
Oh, i see now. Got it.

I moved that part of code to present it in better way. This is how it looks in my project

void engine::ProcessEvents()
{
    while (window.pollEvent(event))
    {
        switch (event.type)
        {
            case sf::Event::KeyPressed:
                handlePlayerInput(event.key.code, true);
                break;
               
            case sf::Event::KeyReleased:
                handlePlayerInput(event.key.code, false);
                break;
               
            case sf::Event::Closed:
                window.close();
                break;
        }
    }
}
 

void engine::handlePlayerInput(sf::Keyboard::Key key, bool isPressed)
{
    if(key == sf::Keyboard::W && isPressed == true)
    {
        Player.movePlayer(0);
    }
   
    else if(key == sf::Keyboard::S && isPressed == true)
    {
        Player.movePlayer(1);
    }
   
    else if(key == sf::Keyboard::A && isPressed == true)
    {
        Player.movePlayer(2);
    }
   
    else if(key == sf::Keyboard::D && isPressed == true)
    {
        Player.movePlayer(3);
    }
   
}
 

void cPlayer::movePlayer(unsigned short direction)
{
    if(direction == 0) //up
    {
        Player.move(0, -Speed);
        animator.playAnimation("moveUp", true);
    }
   
    if(direction == 1) //down
    {
        Player.move(0, Speed);
        animator.playAnimation("moveDown", true);
    }
   
    if(direction == 2) //left
    {
        Player.move(-Speed, 0);
        animator.playAnimation("moveLeft", true);
    }
   
    if(direction == 3) //right
    {
        Player.move(Speed, 0);
        animator.playAnimation("moveRight", true);
    }

    animator.update(Clock.restart());
    animator.animate(Player);
}
 

Sometimes when i press a few times same key, for example "W" then texture change to next but stay static.

3
Graphics / Re: Animation in thor does not play.
« on: May 15, 2017, 07:43:00 pm »
You wrote about thor, didn't you? I downloaded it maybe a week ago so i think it is up-to-date.

I thought i did it right because i had seen some posts on this forum and tutorial on thor website. How can i solve it then?

4
Graphics / Animation in thor does not play.
« on: May 15, 2017, 07:20:13 pm »
Hi, I have got a problem with animation. I added frames to thor::FrameAnimation and next added it to thor::animator. Everything what it do is showing only one frame. I researched my problem and found nothing. I am using current version of SFML and thor on Xcode on mac. Could you help me?

I cut out only a few lines of code. In project i have it in separate classes.

thor::Animator<sf::Sprite, std::string> animator;
   
    thor::FrameAnimation moveLeft;
   
    sf::Sprite sPlayer;
   
    sPlayer.setTexture(Textures);
    sPlayer.setTextureRect(sf::IntRect (362, 248, 37, 59)); //set starting texture
   
   
   
    moveLeft.addFrame(1.f, sf::IntRect (320, 304, 42, 58));
    moveLeft.addFrame(2.f, sf::IntRect (320, 186, 42, 59));
    moveLeft.addFrame(3.f, sf::IntRect (320, 304, 42, 58));
    moveLeft.addFrame(4.f, sf::IntRect (320, 186, 42, 59));
    animator.addAnimation("moveLeft", moveLeft, sf::seconds(4));

   
    while (window.isOpen()) // Start the game loop
    {
        ProcessEvents();
        Render();
        animator.playAnimation("moveLeft");
        animator.update(Clock.restart());
        animator.animate(sPlayer);
        window.draw(sPlayer);
        window.display();
        window.clear();
    }
}

 

Pages: [1]