【发布时间】:2015-06-10 23:21:42
【问题描述】:
我正在学习 SDL,但遇到了一个令人沮丧的问题。代码如下。
即使有一个循环使程序保持活动状态,但当我加载图像并将源矩形的 x 值更改为动画时,加载的图像会在 15 秒后消失。静态图像不会发生这种情况。只有动画。我确定我缺少一个简单的东西,但我看不到它。
void update(){
rect1.x = 62 * int ( (SDL_GetTicks() / 100) % 12);
/* 62 is the width of a frame, 12 is the number of frames */
}
void shark(){
surface = IMG_Load("s1.png");
if (surface != 0){
texture = SDL_CreateTextureFromSurface(renderer,surface);
SDL_FreeSurface(surface);
}
rect1.y = 0;
rect1.h = 90;
rect1.w = 60;
rect2.x = 0;
rect2.y = 0;
rect2.h = rect1.h+30; // enlarging the image
rect2.w = rect1.w+30;
SDL_RenderCopy(renderer,texture,&rect1,&rect2);
}
void render(){
SDL_SetRenderDrawColor(renderer, 0, 0, 100, 150);
SDL_RenderPresent(renderer);
SDL_RenderClear(renderer);
}
和主要的
update();
shark();
render();
SDL_image 标头已包含、链接、dll 存在。会不会是dll坏了?
为了简单起见,我省略了程序的其余部分。如果这还不够,我可以发布整个内容。
【问题讨论】:
-
至少展示你的整个循环。
标签: c++ visual-studio sdl