Page 1 of 1

[solved] How to Animate gifs

Posted: Thu Sep 02, 2010 06:45
by spracle
hi~I know 0.7.2 added animation system, but I'm still confused about how to animate gifs in cegui?

Anyone could help me,here?

Re: How to Animate gifs

Posted: Thu Sep 02, 2010 09:06
by CrazyEddie
You can not directly use animated 'gif' files, this will probably never change; CEGUI does not work like that.

To do image flipping animation, you need to load the images to be used as Images defined on an Imageset (it could be possible to have your own code that would return an appropriate Imageset given a .gif file, but this is not provided within CEGUI). You can then use those Image names within the animation system to flip to the new image at an appropriate time. I can't give a concrete example at the moment, but play around with it, and if you can't figure it out, post what you have and someone will point you in the right direction.

CE.

Re: How to Animate gifs

Posted: Fri Sep 03, 2010 03:03
by spracle
Seem that I kind of understand how Animation System works,and i tested it in the ceguiSamples

Changed code of "Sample_FirstWindow.cpp" in Sample_firstWindow is following:

Code: Select all

#include "Sample_FirstWindow.h"
#include "CEGUI.h"

int main(int /*argc*/, char* /*argv*/[])
{

   FirstWindowSample app;
   return app.run();
}

bool FirstWindowSample::initialiseSample()
{
   using namespace CEGUI;

   CEGUI::Animation* anim = CEGUI::AnimationManager::getSingleton().createAnimation("Testing");
   anim->setDuration(0.3f); // duration in seconds
   anim->setReplayMode(CEGUI::Animation::RM_Once); // when this animation is started, only play it once, then stop

   CEGUI::Affector* affector1 = anim->createAffector("YRotation", "float");
   affector1->createKeyFrame(0.0f, "0.0");
   affector1->createKeyFrame(0.3f, "10.0", CEGUI::KeyFrame::P_QuadraticAccelerating);


   CEGUI::Affector* affector2 = anim->createAffector("Alpha", "float");
   affector2->createKeyFrame(0.0f, "1.0"); // at 0.0 seconds, set alpha to 0.5
   affector2->createKeyFrame(0.3f, "0.5", CEGUI::KeyFrame::P_QuadraticDecelerating); // at 1.0 seconds, set alpha to 1.0, now decelerating!

   CEGUI::Affector* affector3 = anim->createAffector("Text", "float");
   affector3->createKeyFrame(0.0f, "AAAA"); // at 0.0 seconds, set alpha to 0.5
   affector3->createKeyFrame(0.3f, "BBBB", CEGUI::KeyFrame::P_QuadraticDecelerating);

   CEGUI::Affector* affector4 = anim->createAffector("Visible", "bool");
   affector4->createKeyFrame(0.0f, "true"); // at 0.0 seconds, set alpha to 0.5
   affector4->createKeyFrame(0.3f, "false", CEGUI::KeyFrame::P_QuadraticDecelerating);

   SchemeManager::getSingleton().create("TaharezLook.scheme");

   System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");

   WindowManager& winMgr = WindowManager::getSingleton();
   DefaultWindow* root = (DefaultWindow*)winMgr.createWindow("DefaultWindow", "Root");
   CEGUI::Font& font = FontManager::getSingleton().createFreeTypeFont("DefaultFont", 10/*pt*/, true, "simhei.ttf");
   System::getSingleton().setDefaultFont("DefaultFont");

   System::getSingleton().setGUISheet(root);

   FrameWindow* wnd = (FrameWindow*)winMgr.createWindow("TaharezLook/FrameWindow", "Demo Window");

   root->addChildWindow(wnd);

   CEGUI::AnimationInstance* instance = CEGUI::AnimationManager::getSingleton().instantiateAnimation(anim);

   instance->setTargetWindow(wnd);

   instance->start();

   wnd->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.25f)));
   wnd->setSize(UVector2(cegui_reldim(0.5f), cegui_reldim( 0.5f)));

   wnd->setMaxSize(UVector2(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
   wnd->setMinSize(UVector2(cegui_reldim(0.1f), cegui_reldim( 0.1f)));


   wnd->subscribeEvent(CEGUI::Window::EventMouseEntersArea, CEGUI::Event::Subscriber(&CEGUI::AnimationInstance::handleStart, instance));

   return true;
}
void FirstWindowSample::cleanupSample()
{
   // nothing to do here!
}



But it couldn't work .Did I miss something?

Re: How to Animate gifs

Posted: Fri Sep 03, 2010 09:05
by spracle
hoho~ Problems solved :D
It's about "injectTimepulse()" function, and it's my problem~

Re: [solved] How to Animate gifs

Posted: Wed Mar 23, 2011 09:04
by ogre2012
1.first ,you must read this article
http://www.cegui.org.uk/wiki/index.php/Animation_System
you can find the resource in this web
http://u.115.com/file/f9f717c629
the layout's name is Format.layout.

2.you can add the following in the VanillaSkin.scheme file( "the Vanilla/StaticImage")

Code: Select all

<Animations>
         <AnimationDefinition name="Testing" duration="0.3" replayMode="once">
              <Affector property="Image" interpolator="String">
                   <KeyFrame position="0.1" value="set:guangbiao image:NewImage1" />
                   <KeyFrame position="0.2" progression="discrete" value="set:guangbiao image:NewImage2" />
                   <KeyFrame position="0.3" progression="discrete" value="set:guangbiao image:NewImage3" />
                </Affector>
            <Affector property="Alpha" interpolator="float">
               <KeyFrame position="0.0" value="1.0" />
               <KeyFrame position="0.3" value="0.5" />
            </Affector>
            <Affector property="XRotation" interpolator="float">
               <KeyFrame position="0.0" value="0" />
               <KeyFrame position="0.3" value="10" />
            </Affector>
            <Affector property="Text" interpolator="String">
               <KeyFrame position="0.0" value="AAAA" />
               <KeyFrame position="0.3" value="BBBB" />
            </Affector>
         </AnimationDefinition>
      </Animations>

3. in the Sample_FalagardDemo1.cpp file

CEGUI::Window* imageComponent;

Code: Select all

{
      // this affector will again use String to change the Image
      CEGUI::Affector* affector = anim->createAffector("Image", "String");

      affector->createKeyFrame(0.1f, "set:guangbiao image:NewImage1"); // at 0.1 seconds
      affector->createKeyFrame(0.2f, "set:guangbiao image:NewImage2", CEGUI::KeyFrame::P_Linear); // at 0.2 seconds
       affector->createKeyFrame(0.3f, "set:guangbiao image:NewImage3", CEGUI::KeyFrame::P_Linear);
   }

   //CEGUI::MouseCursor

   instance = CEGUI::AnimationManager::getSingleton().instantiateAnimation(anim);
   // after we instantiate the animation, we have to set its target window
   instance->setTargetWindow(imageComponent);  //textComponent  imageComponent

4. you can used the file in my resource.rar.

Re: [solved] How to Animate gifs

Posted: Thu Mar 24, 2011 16:48
by Kulik
Just for the record, you have to define the animation once, via C++ code (or python/lua) OR via XML (looknfeel, animations.xml). You can do it twice but it's kind of wasteful. I also can't figure out how you start the animation. You have to either instance->start() or subscribe the "Start" action to some Event.

Re: [solved] How to Animate gifs

Posted: Thu Nov 17, 2011 08:06
by jack1104
Hello,

I'm trying make an icon with changing image, I reference the code by ogre2012 in my WidgetLook:

Code: Select all

<WidgetLook name="game1/Button">
...
<AnimationDefinition name="Testing" duration="0.3" replayMode="once">
              <Affector property="Image" interpolator="String">
                   <KeyFrame position="0.1" value="set:game1 image:myImage1" />
                   <KeyFrame position="0.2" progression="discrete" value="set:game1 image:myImage2" />
                   <KeyFrame position="0.3" progression="discrete" value="set:game1 image:myImage3" />
              </Affector>
...
<Subscription event="MouseEntersArea" action="Start" />
...
</WidgetLook>


But I get an error at CEGUIPropertySet.cpp line 124:

Code: Select all

CEGUI_THROW(UnknownObjectException("There is no Property named '" + name + "' available in the set."));

name = "image" occur an error here.
But I try the name(<Affector property>) = "float", "UnifiedHeight"...etc, is working no problem.

I have no idea how "There is no Property named '" + name + "' available in the set." happened.
I'm new with CEGUI and my english is poor, forgive me :oops:

Can anyone help me?

Re: [solved] How to Animate gifs

Posted: Thu Nov 17, 2011 09:17
by CrazyEddie
Don't double-post (especially not into other peoples topics). One and only warning ;)

Thanks

CE.