CEGUI 动画系统
1.准备动画图片资源
自己新建个imageset,把动画每帧的图片放进去,定义好相应的Image
<?xml version="1.0" encoding="UTF-8"?> <Imageset Name="aniImagesets" Imagefile="animation.tga" NativeHorzRes="1024" NativeVertRes="768" > <Image Name="ani1" XPos="0" YPos="0" Width="146" Height="151" /> <Image Name="ani2" XPos="146" YPos="0" Width="146" Height="151" /> <Image Name="ani3" XPos="292" YPos="0" Width="146" Height="151" /> <Image Name="ani4" XPos="438" YPos="0" Width="146" Height="151" /> <Image Name="ani5" XPos="584" YPos="0" Width="146" Height="151" /> </Imageset>
2.新建动画的配置文件myAnimation.xml
<?xml version="1.0" ?> <Animations> <AnimationDefinition name="MoveToLeft" duration="0.8" replayMode="loop"> <Affector property="Image" interpolator="String"> <KeyFrame position="0.0" value="set:aniImagesets image:ani1" /> <KeyFrame position="0.2" progression="discrete" value="set:aniImagesets image:ani2" /> <KeyFrame position="0.4" progression="discrete" value="set:aniImagesets image:ani3" /> <KeyFrame position="0.6" progression="discrete" value="set:aniImagesets image:ani4" /> <KeyFrame position="0.8" progression="discrete" value="set:aniImagesets image:ani5" /> <Subscription event="MouseEntersArea" action="Start" /> </Affector> </AnimationDefinition> </Animations>
name指的是动画的名字,duration 指的是总时间,replayMode 指的是播放模式,有once(只播放一次),loop(循环播放);下面的position中指的是每帧中的起始时间,value指的是对应的图片.
3.在代码中生成新的动画实例,绑定到某个窗口中,且该窗口要有Image的属,设置ALPHA等属性,这样窗口不会盖住背景, 有透明效果
//动画 Window* staticImage = wmgr.createWindow("WindowsLook/StaticImage", "staticImage"); staticImage->setProperty(("UnifiedAreaRect"),("{{0.2,20},{0.2,20},{0.2,200},{0.2,150}}")); staticImage->setProperty("FrameEnabled", "false"); staticImage->setProperty("AlwaysOnTop", "true"); //staticImage->setProperty("Alpha", "0.2"); staticImage->setProperty("BackgroundEnabled", "false"); staticImage->setProperty("FrameEnabled", "false"); wRoot->addChildWindow(staticImage); //载入定义动画的文件 AnimationManager::getSingleton().loadAnimationsFromXML("myAnimation2.xml"); //找到一个动画定义 Animation* animation = CEGUI::AnimationManager::getSingleton().getAnimation("MoveToLeft"); //生成相应的动画实例,我们真正用的是动画实例 AnimationInstance* ani = CEGUI::AnimationManager::getSingleton().instantiateAnimation(animation); ani->setTarget(staticImage);//绑定到相应的窗口,这个窗口一定要有Image的属性,不然会报错 ani->start(); ani->setSpeed(1.0f);//设置动画加速
4.在循环函数中添加时间脉冲,注意参数以秒为单位
//里面是float的时间参数 CEGUI::System::getSingleton().injectTimePulse(timeSinceLastFrame)