• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 96  文章 - 255  trackbacks - 0
            <2008年9月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            E-mail:zbln426@163.com QQ:85132383 長期尋找對戰(zhàn)略游戲感興趣的合作伙伴。

            常用鏈接

            留言簿(21)

            隨筆分類

            隨筆檔案

            SDL相關(guān)網(wǎng)站

            我的個人網(wǎng)頁

            我的小游戲

            資源下載

            搜索

            •  

            積分與排名

            • 積分 - 494280
            • 排名 - 39

            最新評論

            閱讀排行榜

            評論排行榜

            作者:龍飛

            7.1:演示程序源代碼

                    今天因為一個網(wǎng)上的朋友的請求,做個一個關(guān)于鼠標(biāo)事件的演示程序。實(shí)際上,可以完全用到前面我們構(gòu)造的類和類方法,這里送上主程序,供大家參考。其他兩個文件和圖片文件均不需要任何改變。
            #include "SurfaceClass.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;
                ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT);

                
            //Create 2 SDL surface for the screen that just created.
                DisplaySurface backGround("bg.bmp", screen);
                DisplaySurface frontImage(
            "image.bmp", screen);

                
            //Blit backGround surface to screen and flip the screen.
                backGround.blit();
                screen.flip();

                
            //moving image's coordinate.
                int xpos = 0;
                
            int ypos = 0;
                
            //mouse's coordinate.
                int px = 0;
                
            int py = 0;
                
            //moving image's size.
                const int IMG_WIDTH = 128;
                
            const int IMG_HEIGHT = 128;
                
            //main loop.
                bool gameOver = false;
                
            while( gameOver == false ){
                    
            //press ESC or click X to quit.
                    SDL_Event gameEvent;
                    
            while ( SDL_PollEvent(&gameEvent) != 0 ){
                        
            if ( gameEvent.type == SDL_QUIT ){
                            gameOver 
            = true;
                        }
                        
            if ( gameEvent.type == SDL_KEYUP ){
                            
            if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                                gameOver 
            = true;
                            }
                        }
                        
            //mouse event
                        if ( gameEvent.type == SDL_MOUSEMOTION ) {
                            px 
            = gameEvent.motion.x;
                            py 
            = gameEvent.motion.y;
                        }
                    }

                    
            if ( xpos < px )
                        xpos
            ++;
                    
            if ( xpos > px )
                        xpos
            --;
                    
            if ( ypos < py )
                        ypos
            ++;
                    
            if ( ypos > py )
                        ypos
            --;

                    backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
                    frontImage.blit(xpos, ypos);
                    screen.flip();
                }

                
            return 0;
            }
            posted on 2008-03-02 22:02 lf426 閱讀(3400) 評論(6)  編輯 收藏 引用 所屬分類: SDL入門教程

            FeedBack:
            # re: SDL入門教程(五):7、鼠標(biāo)事件演示,代碼重用 2008-06-12 16:10 huahua
            為什么我調(diào)試的時候,定義的類#include "SurfaceClass.h"調(diào)用是成功的,但是
            ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT);時卻說無法識別 undefined reference to 'ScreenSurface ::..........................  回復(fù)  更多評論
              
            # re: SDL入門教程(五):7、鼠標(biāo)事件演示,代碼重用[未登錄] 2008-06-12 18:46 lf426
            沒有和SurfaceClass.cpp一起編譯?  回復(fù)  更多評論
              
            # re: SDL入門教程(五):7、鼠標(biāo)事件演示,代碼重用 2009-06-15 17:57 georangel
            int game(int argc ,char* argv[])

            //mouse event
            if ( gameEvent.type == SDL_MOUSEMOTION ) {
            // delta_x, delta_y 的默認(rèn)值如果設(shè)置為0,
            // 可以在需要刷新的時候,
            // 在xpos, ypos沒有改變之前擦除“變動目標(biāo)”原來的區(qū)域
            backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
            px = gameEvent.motion.x;
            py = gameEvent.motion.y;
            }
              回復(fù)  更多評論
              
            # re: SDL入門教程(五):7、鼠標(biāo)事件演示,代碼重用 2011-01-13 10:21 笑傲暖壺
            您好,我想問一下,在SDL中能不能控制光標(biāo)的大???  回復(fù)  更多評論
              
            # re: SDL入門教程(五):7、鼠標(biāo)事件演示,代碼重用[未登錄] 2011-01-15 13:23 lf426
            簡單的說,不能。光標(biāo)屬于操作系統(tǒng)的GUI元素@笑傲暖壺
              回復(fù)  更多評論
              
            # re: SDL入門教程(五):7、鼠標(biāo)事件演示,代碼重用 2013-04-07 17:30 ylguo
            可以的,SDL里的光標(biāo)是自己畫的。并不是用的系統(tǒng)gui自帶的那個鼠標(biāo),找找源碼@笑傲暖壺
              回復(fù)  更多評論
              
            久久AAAA片一区二区| 中文字幕久久亚洲一区| 久久精品国产亚洲av麻豆蜜芽| 99久久精品国产高清一区二区| 少妇精品久久久一区二区三区| 伊人色综合九久久天天蜜桃| 四虎影视久久久免费| 无码8090精品久久一区| 亚洲国产精品综合久久网络| 亚洲国产成人久久综合野外| 国产免费久久精品99re丫y| 久久只有这精品99| 无码精品久久久久久人妻中字| 无码精品久久久天天影视| 国产精品美女久久久m| 亚洲伊人久久大香线蕉苏妲己| 久久久久久国产精品无码下载| 日日狠狠久久偷偷色综合免费| 久久久久久久久久久久久久| 亚洲AV日韩精品久久久久| 99久久免费国产精精品| 久久激情五月丁香伊人| 亚洲人成电影网站久久| 久久久一本精品99久久精品88| 久久久久久久综合日本亚洲| 亚洲欧美国产日韩综合久久 | 久久精品亚洲一区二区三区浴池 | 国产国产成人精品久久| 久久99国产精品成人欧美| 久久亚洲国产成人影院| 久久se精品一区二区| 亚洲欧美日韩精品久久亚洲区| 久久综合亚洲欧美成人| 久久毛片免费看一区二区三区| 一本一道久久综合狠狠老| 久久精品亚洲男人的天堂| 久久综合精品国产二区无码| 久久亚洲精品无码观看不卡| 精品久久久无码人妻中文字幕豆芽| 久久精品亚洲男人的天堂| 国产Av激情久久无码天堂 |