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

Author Topic: renderWindow.GetFrameTime?  (Read 2728 times)

0 Members and 2 Guests are viewing this topic.

Flojer0

  • Newbie
  • *
  • Posts: 3
    • View Profile
renderWindow.GetFrameTime?
« on: January 24, 2012, 04:52:39 pm »
trying to get thor and sfml up and running for sprite animations. for my latest in errors I get from code::blocks:

sf::RenderWindow’ has no member named ‘GetFrameTime’|

and sure enough I see nothing under render window title as such. here is the source file.



#include <Thor/Animation.hpp>
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 200), "Thor Animation");
    window.SetFramerateLimit(20);
    window.EnableKeyRepeat(false);

    // Instruction text
    sf::Text instructions(
        "D:  Play drive animation (loop)\n"
        "F:  Play fire animation\n"
        "S:  Stop current animation\n"
        "Esc:  Quit");
    instructions.SetCharacterSize(12);
    instructions.SetColor(sf::Color::White);

    // Load image that contains animation steps
    sf::Image image;
    if (!image.LoadFromFile("Media/animation.png"))
        return 1;
    image.CreateMaskFromColor(sf::Color::White);

    // Create texture based on sf::Image
    sf::Texture texture;
    if (!texture.LoadFromImage(image))
        return 1;

    // Create sprite and object that animates it
    sf::Sprite sprite(texture);
    sprite.SetPosition(100.f, 100.f);
    thor::Animator animator;

    // Specify static subrect which is shown unless an other animation is active
    thor::FrameAnimation::Ptr defaultAnim = thor::FrameAnimation::Create();
    defaultAnim->AddFrame(1.f, sf::IntRect(0, 21, 44, 21));
    animator.SetDefaultAnimation(defaultAnim, 1.f);

    // Create first animation and register it at the animator
    thor::FrameAnimation::Ptr drive = thor::FrameAnimation::Create();
    for (unsigned int i = 0; i < 3; ++i)
        drive->AddFrame(1.f, sf::IntRect(0, 21*i, 44, 21));
    animator.AddAnimation("drive", drive, 0.4f);

    // Create second animation and register it at the animator
    thor::FrameAnimation::Ptr fire = thor::FrameAnimation::Create();
    for (unsigned int i = 0; i < 4; ++i)
        fire->AddFrame(1.f, sf::IntRect(44, 21*i, 49, 21));
    animator.AddAnimation("fire", fire, 0.3f);

    // Main loop
    for (;;)
    {
        // Handle events
        sf::Event event;
        while (window.PollEvent(event))
        {
            if (event.Type == sf::Event::KeyPressed)
            {
                switch (event.Key.Code)
                {
                case sf::Keyboard::D:
                    animator.PlayAnimation("drive", true);
                    break;
                case sf::Keyboard::F:
                    animator.PlayAnimation("fire");
                    break;
                case sf::Keyboard::S:
                    animator.StopAnimation();
                    break;
                case sf::Keyboard::Escape:
                    return 0;
                }
            }
            else if (event.Type == sf::Event::Closed)
            {
                return 0;
            }
        }

        // Update animator and apply current animation state to the sprite
        animator.Update(window.GetFrameTime() / 1000.f);
        animator.Animate(sprite);

        // Draw everything
        window.Clear(sf::Color(50, 50, 50));
        window.Draw(instructions);
        window.Draw(sprite);
        window.Display();
    }
}


thanks

texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
renderWindow.GetFrameTime?
« Reply #1 on: January 24, 2012, 04:59:00 pm »
GetFrameTime was removed. There is another recent topic about this: http://www.sfml-dev.org/forum/viewtopic.php?t=6831.
TGUI: C++ SFML GUI

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
renderWindow.GetFrameTime?
« Reply #2 on: January 24, 2012, 09:31:04 pm »
This has already been updated in Thor. The Animation API changed also slightly, it uses now sf::Time instead of float for times.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything