您的位置:首页 > 其它

SDL学习(4)图片自动变亮和变暗

2016-03-21 00:26 260 查看
1;亮度的自动调节主要有一断判断语句

bool b=true; //定义一个bool类型用于判定

    int a=255;  //255即为最亮

 bool quit =false ;

    while (!quit ){

        while (SDL_PollEvent(&event)){

            if (event.type==SDL_QUIT){

                quit =true ;

            }

        }

        SDL_RenderClear(rend);

        SDL_SetTextureAlphaMod(qq1,a);

        if (b==true){    //主要由这一段条件函数来调节  具体的相信在之前已经接触过几次 就不解释了

            a--;          

            if(a==0){

                b=false;

            }

        }

        else {

            a++;

            if(a==255){

                b=true;

            }

        }

2然一个图片产生阴影尾巴

    SDL_Surface*surface =SDL_LoadBMP("qq1.bmp");//因为要产生阴影所以要加一个较暗的图片

    SDL_Surface*surface2 =SDL_LoadBMP("qq.bmp");

    SDL_Texture*qq1=SDL_CreateTextureFromSurface(rend,surface);

    SDL_Texture*qq=SDL_CreateTextureFromSurface(rend,surface2);

//把图片贴上去

  SDL_Surface*surface =SDL_LoadBMP("qq1.bmp");

    SDL_Surface*surface2 =SDL_LoadBMP("qq.bmp");

    SDL_Texture*qq1=SDL_CreateTextureFromSurface(rend,surface);

    SDL_Texture*qq=SDL_CreateTextureFromSurface(rend,surface2);

//调节透明度

SDL_SetTextureBlendMode(qq1,SDL_BLENDMODE_BLEND);;

    SDL_SetTextureBlendMode(qq,SDL_BLENDMODE_BLEND);

    SDL_SetTextureAlphaMod(qq,1000);//调透明度  越小越长

//最后加上一图片随着鼠标运动而运动的代码

bool quit =false ;

    while (!quit ){

        while (SDL_PollEvent(&event)){

            if (event.type==SDL_QUIT){

                quit =true ;

            }

            else if(event.type==SDL_MOUSEMOTION){

                rect.x=event.motion.x-rect.w/2;//后面-rect.w/2是图片的宽度目的是然鼠标位于图片正中间

                rect.y=event.motion.y-rect.h/2;

            }

        }

      //  SDL_RenderClear(rend);

        SDL_RenderCopy(rend,qq,NULL,&rect);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: