• <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年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

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

            常用鏈接

            留言簿(21)

            隨筆分類

            隨筆檔案

            SDL相關網站

            我的個人網頁

            我的小游戲

            資源下載

            搜索

            •  

            積分與排名

            • 積分 - 493132
            • 排名 - 39

            最新評論

            閱讀排行榜

            評論排行榜

            作者:龍飛

            7.1:演示程序源代碼

                    今天因為一個網上的朋友的請求,做個一個關于鼠標事件的演示程序。實際上,可以完全用到前面我們構造的類和類方法,這里送上主程序,供大家參考。其他兩個文件和圖片文件均不需要任何改變。
            #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 閱讀(3383) 評論(6)  編輯 收藏 引用 所屬分類: SDL入門教程

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

            //mouse event
            if ( gameEvent.type == SDL_MOUSEMOTION ) {
            // delta_x, delta_y 的默認值如果設置為0,
            // 可以在需要刷新的時候,
            // 在xpos, ypos沒有改變之前擦除“變動目標”原來的區域
            backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
            px = gameEvent.motion.x;
            py = gameEvent.motion.y;
            }
              回復  更多評論
              
            # re: SDL入門教程(五):7、鼠標事件演示,代碼重用 2011-01-13 10:21 笑傲暖壺
            您好,我想問一下,在SDL中能不能控制光標的大小?  回復  更多評論
              
            # re: SDL入門教程(五):7、鼠標事件演示,代碼重用[未登錄] 2011-01-15 13:23 lf426
            簡單的說,不能。光標屬于操作系統的GUI元素@笑傲暖壺
              回復  更多評論
              
            # re: SDL入門教程(五):7、鼠標事件演示,代碼重用 2013-04-07 17:30 ylguo
            可以的,SDL里的光標是自己畫的。并不是用的系統gui自帶的那個鼠標,找找源碼@笑傲暖壺
              回復  更多評論
              
            国产精品免费看久久久| 久久午夜无码鲁丝片午夜精品| 久久精品综合网| 久久99国产综合精品| 久久精品不卡| 无码超乳爆乳中文字幕久久| A级毛片无码久久精品免费| 亚洲一区精品伊人久久伊人| 99久久精品费精品国产一区二区| 久久国产精品波多野结衣AV| 久久久精品人妻一区二区三区蜜桃 | 欧美日韩精品久久久免费观看| 无码人妻久久一区二区三区免费丨| 久久综合九色综合欧美狠狠| 亚洲va久久久噜噜噜久久狠狠| 久久久久婷婷| 色成年激情久久综合| 久久久亚洲欧洲日产国码aⅴ| 亚洲国产日韩欧美久久| 久久久久久久尹人综合网亚洲| 精品国产99久久久久久麻豆| 久久久无码精品亚洲日韩软件| 久久精品www| 狠狠色丁香婷婷综合久久来| 久久久久久人妻无码| 国产A三级久久精品| 伊人久久国产免费观看视频| 久久人人超碰精品CAOPOREN| 精品久久久久久久久久久久久久久| 亚洲国产成人久久精品动漫| 久久99精品久久久久久| 久久久久久狠狠丁香| 91精品久久久久久无码| 精品水蜜桃久久久久久久| 亚洲国产精品久久| 大蕉久久伊人中文字幕| 国产69精品久久久久99| 久久久久久极精品久久久| 亚洲国产高清精品线久久| 久久人人爽人人爽人人片AV不 | 久久久精品人妻一区二区三区蜜桃 |