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);
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);
相关文章推荐
- NODE.JS+EXPRESS.JS+百度BAE服务 构建学术个人主页
- 关于回调方法
- 行为驱动开发(BDD)
- 319. Bulb Switcher
- Spring MVC 与ExtJS完美集成
- 不借第三个变量两变量互换
- python编码及文件编ASCII,Unicode和UTF-8相关知识
- C++ 学习 笔记(菜鸟级,自我备忘)
- 诗词赏析
- Jquery学习
- wds
- 安卓学习_自定义属性
- Vue.js
- 我的csdn
- IOS学习 iPad控件:POP控件器,分割窗口、浮动窗口、模态视图的使用
- yum 和 apt-get
- Android的shape,两个圆角例子
- 浅析android中AsyncTask
- Net程序员学习Linux
- 20159320 《网络攻防实践》第3周教材学习总结