]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/animate.cpp
Fix initialization issues in the Animate action
[libs/demoscene.git] / source / animate.cpp
index cd6cda1d8faee1ccca2f6ecdd7cf19abefbf0c1b..a7e406d73ae80c3428b5fe91d214820dffc645bf 100644 (file)
@@ -8,14 +8,17 @@ namespace DemoScene {
 
 Animate::Animate():
        target(0),
+       target_obj(0),
        anim(0),
        stacked(false),
        player(0)
 { }
 
-Animate::Animate(GL::Placeable &t, const GL::Animation &a, GL::AnimationPlayer &p):
+Animate::Animate(GL::Placeable &t, const GL::Animation &a, GL::AnimationPlayer &p, bool s):
        target(&t),
+       target_obj(0),
        anim(&a),
+       stacked(s),
        player(&p)
 { }
 
@@ -34,10 +37,20 @@ void Animate::start(float, float d)
        float speed = 1.0f;
        if(!anim->is_looping() && d)
                speed = (anim->get_duration()/Time::sec)/d;
-       if(stacked)
-               player->play_stacked(*target, *anim, speed);
+       if(target_obj)
+       {
+               if(stacked)
+                       player->play_stacked(*target_obj, *anim, speed);
+               else
+                       player->play(*target_obj, *anim, speed);
+       }
        else
-               player->play(*target, *anim, speed);
+       {
+               if(stacked)
+                       player->play_stacked(*target, *anim, speed);
+               else
+                       player->play(*target, *anim, speed);
+       }
 }
 
 
@@ -58,6 +71,7 @@ void Animate::Loader::animation(const string &n)
 void Animate::Loader::target(const string &n)
 {
        obj.target = &demo.get_thing<GL::Placeable>(n);
+       obj.target_obj = dynamic_cast<GL::AnimatedObject *>(obj.target);
 }
 
 } // namespace DemoScene