Cegui动画完美实现 .
1.myAnimation.xml脚本(放在datafiles/animations路径中):
一共定义了3个动画,name指的是动画的名字,duration 指的是总时间,replayMode 指的是播放模式,有once(只播放一次),loop(循环播放);下面的position中指的是每帧中的起始时间,value指的是对应的图片.
- <?xml version="1.0" ?>
- <Animations>
- <AnimationDefinition name="MoveToLeft" duration="0.8" replayMode="once">
- <Affector property="Image" interpolator="String">
- <KeyFrame position="0.0" value="set:FairChar image:bcd" />
- <KeyFrame position="0.2" progression="discrete" value="set:FairChar image:bcdLeft1" />
- <KeyFrame position="0.4" progression="discrete" value="set:FairChar image:bcdLeft2" />
- <KeyFrame position="0.6" progression="discrete" value="set:FairChar image:bcdLeft3" />
- </Affector>
- </AnimationDefinition>
- <AnimationDefinition name="MoveToRight" duration="0.8" replayMode="once">
- <Affector property="Image" interpolator="String">
- <KeyFrame position="0.0" value="set:FairChar image:bcdLeft3" />
- <KeyFrame position="0.2" progression="discrete" value="set:FairChar image:bcdLeft2" />
- <KeyFrame position="0.4" progression="discrete" value="set:FairChar image:bcdLeft1" />
- <KeyFrame position="0.6" progression="discrete" value="set:FairChar image:bcd" />
- </Affector>
- </AnimationDefinition>
- <AnimationDefinition name="ChangeMouseCursor" duration="0.8" replayMode="loop">
- <Affector property="Image" interpolator="String">
- <KeyFrame position="0.0" value="set:guangbiao image:NewImage1" />
- <KeyFrame position="0.2" progression="discrete" value="set:guangbiao image:NewImage2" />
- <KeyFrame position="0.4" progression="discrete" value="set:guangbiao image:NewImage3" />
- <KeyFrame position="0.6" progression="discrete" value="set:guangbiao image:NewImage4" />
- </Affector>
- </AnimationDefinition>
- </Animations>
2.修改后的FairChar.imageset 脚本,记着在文件scheme中加入关联
- <?xml version="1.0" encoding="UTF-8"?>
- <Imageset Name="FairChar" Imagefile="FairChar.tga" >
- <Image Name="bcd" XPos="36" YPos="1" Width="93" Height="30" />
- <Image Name="bcdLeft1" XPos="26" YPos="1" Width="93" Height="30" />
- <Image Name="bcdLeft2" XPos="16" YPos="1" Width="93" Height="30" />
- <Image Name="bcdLeft3" XPos="6" YPos="1" Width="93" Height="30" />
- <Image Name="bcdRight1" XPos="46" YPos="1" Width="93" Height="30" />
- <Image Name="bcdRight2" XPos="56" YPos="1" Width="93" Height="30" />
- <Image Name="bcdRight3" XPos="66" YPos="1" Width="93" Height="30" />
- </Imageset>
3.代码:
- //CEGUI::Window* staticImage = winMgr.createWindow("TaharezLook/StaticImage", "staticImage");
- //staticImage->setProperty(("UnifiedAreaRect"),("{{0.2,20},{0.2,20},{0.2,100},{0.2,100}}"));
- //staticImage->setProperty(("FrameEnabled"), ("false"));
- /载入定义动画的文件
- CEGUI::AnimationManager::getSingleton().loadAnimationsFromXML("myAnimation.xml");
- //找到一个动画定义
- CEGUI::Animation* animation = CEGUI::AnimationManager::getSingleton().getAnimation("MoveToLeft ");
- //生成相应的动画实例,我们真正用的是动画实例
- CEGUI::AnimationInstance* ani = CEGUI::AnimationManager::getSingleton().instantiateAnimation(animation);
- //绑定到相应的窗口,这个窗口一定要有Image的属性,不然会报错
- ani->setTarget(staticImage);
- //动画开始
- ani->start();
- //设置动画加速
- ani->setSpeed(5.0f);
【注】 版本是0.7.1之上
1.找到脚本中的动画定义
CEGUI::Animation* animation = CEGUI::AnimationManager::getSingleton().getAnimation("MoveToLeft ");
2.生成新的动画实例,才能绑定到某个窗口中,且该窗口要有Image的属性
3.你可以设置一张map用动画名来绑定动画实例指针
4.如果动画没有成功的话,应该在更新函数中加上cegui的更新函数:
//里面是float的时间参数
CEGUI::System::getSingleton().injectTimePulse(evt.timeSinceLastFrame)