zoukankan      html  css  js  c++  java
  • cegui实现帧动画

    cegui已经是一个功能比较强大的界面编辑器,实现帧动画自然没什么难度。本帖希望对刚学cegui的新手有帮助~_~

    第一步:准备一张图片。


    最好是一张包含几个小相同的小图像, 这些图像连续播放可以产生动画.


    第二步: 将目标图像生成CEGUI的纹理.
    相关示例代码如下:
    CEGUI::Imageset* pImgSet = NULL;
    if (!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent("picSetName"))
    {
    pImgSet = CEGUI::ImagesetManager::getSingleton().createImagesetFromImageFile("picSetName", "picture.jpg");
    }
    else
    {
    pImgSet = CEGUI::ImagesetManager::getSingleton().getImageset("picSetName");
    }
    第三步: 定义一组大小相同的纹理区间.
    假设我们要形成4帧的动画, 在初始化时这里就要这样定义:
    const int frameNum = 4;
    Size sz;
    sz.d_width  = pImgSet->getTexture()->getWidth();
    sz.d_height = pImgset->getTexture()->getHeight();
    pImgset->undefineAllImages();
    CEGUI::Rect area;
    area.d_top = 0;
    area.d_bottom = sz.d_height;
    char buffer[10];
    for (int i=1; i<=frameNum; ++i)
    {
         area.d_left = sz.d_width/frameNum*(i-1);
         area.d_right = sz.d_width/frameNum*i;
         sprintf(buffer, "frame%d", i);
         pImgset->defineImage(buffer, area, Point(0, 0));
    }
    第四步: 播放动画.
    这里我只试过在DefaultWindow类型的窗口上播放动画,其它的没试过
    如果我们的窗口指针是Window* pWin
    那么在每帧渲染里 通常是游戏的Update中设置这样的指令:
    static int i = 1;
    if (i > frameNum)
    {
        i = 1;
    }
    else
    {
         ++i;
    }
    char buffer[10];
    sprintf(buffer, "frame%d", i);
    string mapProPerty = "set:picSetName";
    mapProPerty += " image:";
    mapProperty += buffer;
    pWin->setProperty("Image", mapProPerty);
    就这样, 完成了我们想要的功能.

    相关的代码都是在原来写过的项目上粘过来的, 有些是临时写的, 未经过调试, 大致思路就是这样~_~
    不足之处还请高手多多指教。
    另外用类似的方法还可以制作ogre游戏小地图,具体方方法可以参考http://blog.csdn.net/howlet2/archive/2009/11/26/4876093.aspx

    转载或修改请说明出处:http://blog.csdn.net/howlet2/archive/2009/11/20/4839253.aspx
    作者:howlet
    E-Mial: howlet3@126.com

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/pizi0475/archive/2010/03/19/5396714.aspx

  • 相关阅读:
    关于记忆力:遵从一些原则,自省增加经验,there is a way out of almost everything
    watch watch watch the video! I got almost addicted. Oh what a fuck!!!!
    mysqlhelper
    Android Tools update proxy
    Android Support library
    bat批处理
    Windows PowerShell Exit Codes
    Enable and Use Remote Commands in Windows PowerShell
    power shell remoting
    开发函数计算的正确姿势——轻松解决大依赖部署
  • 原文地址:https://www.cnblogs.com/minggoddess/p/2208424.html
Copyright © 2011-2022 走看看