hge版《见习小恶魔》源代码中新发现的bug和解决方法以及解决vista兼容性问题

来源:互联网 发布:淘宝店招尺寸1920 150 编辑:程序博客网 时间:2024/05/01 15:00
 这些bug可能依赖的编译器不同也会有不同的表现吧……至少以前xp下vs2005的debug版没有问题……orz


第一个bug:guilabel没有初始化rect.x1,rect.y1
解决方法:
构造函数改为
  1. GUILabel::GUILabel(int _id, float x, float y, GdiFont *fnt, char* text, DWORD color, int align) 
  2. : GUIObject () ,m_Font(0),m_FontCN(0) 
  3. {
  4.     bStatic=true;
  5.     bVisible=true;
  6.     bEnabled=true;
  7.     id = _id;
  8.     m_FontCN = fnt;
  9.     m_Pos.x = x;
  10.     m_Pos.y = y;
  11.     m_Color = color;
  12.     rect.x1 = x;
  13.     rect.y1 = y;
  14.     
  15.     m_Align = align;
  16.     ZeroMemory(m_wText,sizeof(m_wText));
  17.     MultiByteToWideChar(CP_ACP,0,text,-1,m_wText,strlen(text));
  18.     SetText(m_wText);
  19. }
  1. void GUILabel::SetText(wchar_t *text){
  2.     SIZE sizeTxt = m_FontCN->GetTextSize(m_wText);
  3.     rect.x2 = rect.x1 + sizeTxt.cx;
  4.     rect.y2 = rect.y1 + sizeTxt.cy;
  5.     
  6.     
  7. }
  8. void GUILabel::SetText(char* text) { 
  9.     m_Text = text;
  10.     ZeroMemory(m_wText,sizeof(m_wText));
  11.     MultiByteToWideChar(CP_ACP,0,text,-1,m_wText,strlen(text));
  12.     SIZE sizeTxt = m_FontCN->GetTextSize(m_wText);
  13.     rect.x2 = rect.x1 + sizeTxt.cx;
  14.     rect.y2 = rect.y1 + sizeTxt.cy;
  15.     
  16. }



第二个bug:guiProbar的goToIndex()依赖的一个TimeLast在Update()里声明为static,并初始化为零,这样做只能保证进度条一被创建就执行GoToInedex时可以正确执行。
解决方法:
将guiProbar.h中的类定义改为
  1. //进度条控件
  2. class GUIProbar : public GUIObject {
  3. public:
  4.     GUIProbar(int id,int x,int y,int w,int h,GdiFont *font,float nmin = 0,float nmax = 999);
  5.     ~GUIProbar();
  6.     void SetBound(float min,float max);
  7.     void SetIndex(float index);
  8.     float GetIndex();
  9.     void SetSprite(const char* backFileName,const char* frontFileName);
  10.     void GoToIndex(float index,float mm);
  11.     void Update(float dt);
  12.     virtual void Render();
  13. private:
  14.     GdiFont*     m_Font; //
  15.     hgeSprite*      backSpr;
  16.     hgeSprite*      frontSpr;
  17.     float           m_min;
  18.     float           m_max;
  19.     float           m_Index;
  20.     float           m_IndexRemain;
  21.     float           m_TimeRemain;
  22.     float           m_TimeLast;
  23. };
  1. void GUIProbar::GoToIndex(float index,float mm)
  2. {
  3.     m_TimeRemain = mm;
  4.     m_IndexRemain = index - m_Index;
  5.     m_TimeLast = 0;
  6. }
  7. void GUIProbar::Update(float dt)
  8. {
  9.     GUIObject::Update(dt);
  10.     float nTemp;
  11.     float nTempIndex;
  12.     m_TimeLast += dt;
  13.     if (m_TimeLast < 0.1)
  14.     {
  15.         return;
  16.     }
  17.     else
  18.     {
  19.         m_TimeLast -= 0.1f;
  20.     }
  21.     if (m_TimeRemain > 0 && m_IndexRemain != 0)
  22.     {
  23.         nTemp = m_IndexRemain * 0.1 / m_TimeRemain;
  24.         nTempIndex = m_IndexRemain;
  25.         if (m_IndexRemain > 0)
  26.         {
  27.             m_IndexRemain -= nTemp;
  28.             if (m_IndexRemain < 0)
  29.             {
  30.                 m_IndexRemain = 0;
  31.                 m_Index += nTempIndex;
  32.                 m_TimeRemain = 0;
  33.                 return;
  34.             }
  35.             else
  36.             {
  37.                 m_Index += nTemp;
  38.                 m_TimeRemain -= 0.1;
  39.             }
  40.         }
  41.         else
  42.         {
  43.             m_IndexRemain -= nTemp;
  44.             if (m_IndexRemain > 0)
  45.             {
  46.                 m_IndexRemain = 0;
  47.                 m_Index += nTempIndex;
  48.                 m_TimeRemain = 0;
  49.                 return;
  50.             }
  51.             else
  52.             {
  53.                 m_Index += nTemp;
  54.                 m_TimeRemain -= 0.1;
  55.             }
  56.         }
  57.     }
  58. }
第三个问题:vista不能使用FontSprite
解决方法:使用FontSprite的继承类GDIFont(中文输入都是微妙的平衡的代码,在这里感谢他)
  1. //原先的代码
  2. GUILabel(int id, float x, float y, FontSprite *fnt, char* text, DWORD color = 0xFFFFFFFF, int align = HGETEXT_LEFT);
  3. //改为
  4. GUILabel(int id, float x, float y, GdiFont *fnt, char* text, DWORD color = 0xFFFFFFFF, int align = HGETEXT_LEFT);
  5. //只要把所有的FontSprite*改为GdiFont*就行。这样vista就能运行,不过字体放大后较丑。
对了,由于类型改了,调用的构造函数也不同了。

  1. void kStageManager::Init(HGE *Hge)
  2. {
  3.     hge = Hge;
  4.     gui = new GUI(hge);
  5.     // 创建矢量字体指针
  6.     m_font[0] = new GdiFont("楷体", 36);//这两行要改
  7.     m_font[1] = new GdiFont("楷体", 24);//这两行要改
  8.     m_font[0]->SetColor(0xff00ffff);
  9.     m_font[1]->SetColor(0xff00ffff);
  10.     cout<<"gui字体创建成功!"<<endl;
  11.     m_Stage[0] = new kStartStage();
  12.     m_Stage[0]->Init();
  13.     cout<<"StartStage创建成功!"<<endl;
  14.     m_Stage[1] = new kTalkStage();
  15.     m_Stage[1]->Init();
  16.     cout<<"TalkStage创建成功!"<<endl;
  17.     m_Stage[2] = new kBattleStage();
  18.     m_Stage[2]->Init();
  19.     cout<<"BattleStage创建成功!"<<endl;
  20.     bChanged = false;
  21. }

原创粉丝点击