• <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
            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

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

            常用鏈接

            留言簿(21)

            隨筆分類(lèi)

            隨筆檔案

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

            我的個(gè)人網(wǎng)頁(yè)

            我的小游戲

            資源下載

            搜索

            •  

            積分與排名

            • 積分 - 493597
            • 排名 - 39

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            作者:龍飛

            7.1:演示程序源代碼

                    今天因?yàn)橐粋€(gè)網(wǎng)上的朋友的請(qǐng)求,做個(gè)一個(gè)關(guān)于鼠標(biāo)事件的演示程序。實(shí)際上,可以完全用到前面我們構(gòu)造的類(lèi)和類(lèi)方法,這里送上主程序,供大家參考。其他兩個(gè)文件和圖片文件均不需要任何改變。
            #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 閱讀(3391) 評(píng)論(6)  編輯 收藏 引用 所屬分類(lèi): SDL入門(mén)教程

            FeedBack:
            # re: SDL入門(mén)教程(五):7、鼠標(biāo)事件演示,代碼重用 2008-06-12 16:10 huahua
            為什么我調(diào)試的時(shí)候,定義的類(lèi)#include "SurfaceClass.h"調(diào)用是成功的,但是
            ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT);時(shí)卻說(shuō)無(wú)法識(shí)別 undefined reference to 'ScreenSurface ::..........................  回復(fù)  更多評(píng)論
              
            # re: SDL入門(mén)教程(五):7、鼠標(biāo)事件演示,代碼重用[未登錄](méi) 2008-06-12 18:46 lf426
            沒(méi)有和SurfaceClass.cpp一起編譯?  回復(fù)  更多評(píng)論
              
            # re: SDL入門(mén)教程(五):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,
            // 可以在需要刷新的時(shí)候,
            // 在xpos, ypos沒(méi)有改變之前擦除“變動(dòng)目標(biāo)”原來(lái)的區(qū)域
            backGround.blit(xpos, ypos, xpos, ypos, IMG_WIDTH, IMG_HEIGHT);
            px = gameEvent.motion.x;
            py = gameEvent.motion.y;
            }
              回復(fù)  更多評(píng)論
              
            # re: SDL入門(mén)教程(五):7、鼠標(biāo)事件演示,代碼重用 2011-01-13 10:21 笑傲暖壺
            您好,我想問(wèn)一下,在SDL中能不能控制光標(biāo)的大小?  回復(fù)  更多評(píng)論
              
            # re: SDL入門(mén)教程(五):7、鼠標(biāo)事件演示,代碼重用[未登錄](méi) 2011-01-15 13:23 lf426
            簡(jiǎn)單的說(shuō),不能。光標(biāo)屬于操作系統(tǒng)的GUI元素@笑傲暖壺
              回復(fù)  更多評(píng)論
              
            # re: SDL入門(mén)教程(五):7、鼠標(biāo)事件演示,代碼重用 2013-04-07 17:30 ylguo
            可以的,SDL里的光標(biāo)是自己畫(huà)的。并不是用的系統(tǒng)gui自帶的那個(gè)鼠標(biāo),找找源碼@笑傲暖壺
              回復(fù)  更多評(píng)論
              
            无遮挡粉嫩小泬久久久久久久| 亚洲精品乱码久久久久久按摩 | 久久综合九色综合久99| 国内精品免费久久影院| 久久久久亚洲av成人网人人软件 | 久久精品国产亚洲Aⅴ蜜臀色欲| 色婷婷久久综合中文久久一本| 国产精品一区二区久久国产| 久久99精品久久久久久不卡| 久久精品国产亚洲AV大全| 色99久久久久高潮综合影院| 99久久成人国产精品免费| 久久这里的只有是精品23| 亚洲午夜精品久久久久久人妖| 久久久久久久久久久精品尤物| 国产国产成人久久精品| 久久久无码精品亚洲日韩按摩 | 亚洲精品成人网久久久久久| 久久成人精品视频| 亚洲AV日韩精品久久久久| 久久久亚洲精品蜜桃臀| 99精品久久久久久久婷婷| 麻豆亚洲AV永久无码精品久久| 久久亚洲高清综合| 国产精品午夜久久| 伊人丁香狠狠色综合久久| 久久天堂AV综合合色蜜桃网| 久久人妻AV中文字幕| 欧美精品丝袜久久久中文字幕| 青青草原综合久久| 99久久精品日本一区二区免费 | 婷婷五月深深久久精品| 久久亚洲AV无码精品色午夜 | 韩国无遮挡三级久久| 久久午夜无码鲁丝片| 久久久久久久久久久久中文字幕 | 久久亚洲AV成人无码电影| 国产精品一久久香蕉国产线看观看| 久久精品a亚洲国产v高清不卡| 久久亚洲中文字幕精品有坂深雪 | 久久99国产精品成人欧美|