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

Author Topic: [THOR2] - Is there a way to link a sound event to a given frame of a animation?  (Read 2907 times)

0 Members and 1 Guest are viewing this topic.

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
Is there a way in Thor to add a sound event to a given frame of an animation?
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Afaik there's no such thing as a sound event. ;)

But it would be usefull if one could query for the current frame being shown, e.g. if frame 1 do this, if frame 2 do that.
With this you chould play a sound as soon as frame X is shown (or even on frame before, since there probably will be some delay...).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

aNewHobby

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
    • Live 4 Ever Or Die Trying
yes that is exactly what I'm asking if possible .
Twitter: @Jyinkies
My Own Little Spot on the Net: - Live4everOrDieTrying.info (Blog)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
That's an interesting idea, but it's quite specific to add a sound just in thor::FrameAnimation. If I add such functionality, I will probably implement a separate sound "animation" that can be played parallel to a graphical one.

Don't forget that you can always write your own animations to achieve virtually everything, so you can already now implement such functionality.
struct SoundAnimation
{
    void addFrame(float relativeDuration,
        const sf::IntRect& subrect, const sf::Sound& sound);

    void operator() (sf::Sprite& animated, float progress) const;
};

You can look at the implementation of thor::FrameAnimation. I'll probably factor out the interval/relative-duration parts, or provide getters, so that one needn't copy-paste the whole code.
« Last Edit: June 23, 2012, 12:30:02 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything