随笔 - 96  文章 - 255  trackbacks - 0
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

E-mail:zbln426@163.com QQ:85132383 长期寻找对战略游戏感兴趣的合作伙伴。

常用链接

留言簿(21)

随笔分类

随笔档案

SDL相关网站

我的个人网页

我的小游戏

资源下载

搜索

  •  

积分与排名

  • 积分 - 485046
  • 排名 - 37

最新评论

阅读排行榜

评论排行榜

作者:龙飞

注意事项:
1、times.ttf文件请到C:\WINDOWS\Fonts下寻找并拷贝到资源目录下。
2、如果您使用VC2008,请用Release编译。原因是,似乎涉及到vector的操作,Runtime Library在debug的时候必须用Multi-theaded Debug DLL (MDd),而Release时候才用Multi-theaded DLL (MD)。而我们亲爱的SDL必须始终用MD,所以,请Release吧。

这是一个检验TextSurface构造函数和析构函数的好例子。我们每一次的鼠标移动,都会导致一个新的TextSurface对象被建立,然后很快的又消亡。

源代码:
//UVi Soft (2008)
//Long Fei (lf426), E-mail: zbln426@163.com

#include 
"SurfaceClass.h"
#include 
"int_to_string.h"

int game(int argc, char* argv[]);
int main(int argc ,char* argv[])
{
    
int mainRtn = 0;
    
try {
        mainRtn 
= game(argc, argv);
    }
    
catch ( const ErrorInfo& info ) {
        info.show();
        
return -1;
    }
    
    
return mainRtn;
}

int game(int argc ,char* argv[])
{
    
//Create a SDL screen.
    const int SCREEN_WIDTH = 640;
    
const int SCREEN_HEIGHT = 480;
    
const std::string WINDOW_NAME = "Mouse Motion";
    ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_NAME);
    
//Fill background.(default is black)
    screen.fillColor();
    screen.flip();
    
    
//Main loop.Press ESC or click X to quit.
    bool gameOver = false;
    SDL_Event gameEvent;
    
int x;
    
int y;
    
while( gameOver == false ){
        
while ( SDL_PollEvent(&gameEvent) != 0 ){
            
if ( gameEvent.type == SDL_MOUSEMOTION ) {
                x 
= gameEvent.motion.x;
                y 
= gameEvent.motion.y;
                std::
string mouse_at = "Mouse at: ";
                mouse_at 
+= ("x = " + int_to_string(x) + "; y = " + int_to_string(y) + ";");
                TextSurface text(
"text", mouse_at, screen);
                screen.fillColor();
                text.blit();
                screen.flip();
            }
            
if ( gameEvent.type == SDL_QUIT ){
                gameOver 
= true;
            }
            
if ( gameEvent.type == SDL_KEYUP ){
                
if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                    gameOver 
= true;
                }
            }
        }
    }

    
return 0;
}
posted on 2008-03-26 21:20 lf426 阅读(1613) 评论(0)  编辑 收藏 引用 所属分类: SDL入门教程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理