有没有熟练SDL C++ 语言的阿?

martinuk 2009-03-10 01:13:46
I am programming an User interface using SDL.
我想写个动画程序就是当用户按钮是, 菜单栏会隐藏到左边屏幕,当再次点击时就弹出来。

What I've done was--
1. when create a menu area, make hold of the under layer of that area(background)
2. when hiding the menubar to the left edge of the screen
while not done loop{
2.0 blit the background back so it covers the menu area
2.1 blit the menu area to the left of 10px say.
}
这样给人眼一种假想菜单栏慢慢的隐藏到了左边。
我的code虽然这个达到了目的,但是不是很流畅,可以看见屏幕一闪一闪的
怎么才能够让它看起来更自然一些?


void printSurface(SDL_Surface* source, int x,int y,int w,int h,
SDL_Surface* dest, int dx, int dy)
{
SDL_Rect src, dst;
src.x = x; src.y = y; src.w = w; src.h = h;
dst.x = dx; dst.y = dy; dst.w = src.w; dst.h = src.h;
//Blit
SDL_BlitSurface( source,&src, dest, &dst );
SDL_Flip(screen);
}


int hide(int direction, My_Surface* p)
{
int Hide_Speed =10;
int dist=p->wi;
int remain = dist%Hide_Speed;
for(int i=0; i<=dist;i+=Hide_Speed){
//cover the original
printSurface(p->background,p->x,p->y, p->wi, p->hi, p->parent, p->x, p->y);
//hide to the left;
printSurface(p->surface,i,0, p->wi, p->hi, p->parent, p->x, p->y);
}
if(remain>0){
//get ride of the remaining
printSurface(p->background,p->x,p->y, p->wi, p->hi, p->parent, p->x, p->y);

}
return 0;
}




...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoomien 2009-03-10
  • 打赏
  • 举报
回复
mark
  • 打赏
  • 举报
回复
不熟,帮up
长安宁 2009-03-10
  • 打赏
  • 举报
回复
int Hide_Speed =10;
把这个步长,变动一下
martinuk 2009-03-10
  • 打赏
  • 举报
回复
解决了

把printSurface里的 SDL_Flip() 放到main event loop 里面
martinuk 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 elovenana 的回复:]
int Hide_Speed =10;
把这个步长,变动一下
[/Quote]

主要问题不再这个我觉得,
我现在的问题是,程序运行的时候可以看见图像一闪一闪的, 说明那个覆盖背景的步骤有问题如果能把它优化,应该就好些

但是又想不到其他办法

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧