LoginSignup
3
1

More than 1 year has passed since last update.

SimpleAnimationでお手軽アニメーション

Last updated at Posted at 2021-12-22

はじめに

Siv3D Advent Calendar 23日目の記事です

SimpleAnimationのつかいかた

SimpleAnimationはOpenSiv3Dv0.6から追加された機能で、簡単にアニメーションの制作ができます。

コード例

# include <Siv3D.hpp>

void Main()
{
    SimpleAnimation animation;
    animation
    .set(U"x", { 0s, 600 }, { 1s, 100 })
    .set(U"y", { 0s, 300 }, { 1s, 500 }, EaseOutBounce);

    const Texture texture{ U"🐈"_emoji };

    while(System::Update())
    {

        if(SimpleGUI::Button(U"move", Vec2(50, 50)))
        {
            // アニメーションを再生
            animation.restart();
        }

        // アニメーションされた縁を描画
        texture.drawAt(animation[U"x"], animation[U"y"]);

    }
}

画面収録-2021-12-03-0.04.45.gif

ちょっとしたリファレンス

SimpleAnimation& set(StringView name, const KeyFrame& a, const KeyFrame& b, double func(double) = Easing::Linear);
name : アニメーション識別用の名前
a : 初期状態 ({秒数, 値}のように記述)
b : 最終状態 ({秒数, 値}のように記述)
func(double) : イージング(かける場合)
アニメーションを追加します。

SimpleAnimation& setLoop(const SecondsF& loopEnd);
loopEnd : 秒数
秒数を指定してループを設定します

void start();
アニメーションをスタート

void pause();
アニメーションを一時停止

bool isDone() const;
アニメーションが終了したかどうか

size_t loopCount() const;
ループした回数

値の取り出しは、[識別名]でできます。つまりこんな感じ

Simpleanimation animation;
animation.set(U"one", {0s, 100}, {1s, 200}).start();

while(System::Update()){
    Print << animation[U"one"]; // 識別名oneのアニメーション(の数値)を表示
}
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1