绘制图像的功能
Draw image in function
我希望在按空格键时绘制图像。这是我的代码:
void drawImage()
{
rect.x = 100;
rect.y = 100;
SDL_Surface *image = IMG_Load("image.png");
SDL_BlitSurface(image, NULL, screen, &rect);
}
这里叫做
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
gameRunning = false;
}
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_SPACE)
{
drawImage();
}
}
}
当我按空格键时,图像没有绘制。怎么了?
翻转屏幕缓冲区(SDL_Surfaces)
行后
SDL_BlitSurface(image, NULL, screen, &rect);
添加SDL_UpdateRect(screen, 0, 0, 0, 0);
函数是否在主循环中没有空格键?
bool draw = false;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
gameRunning = false;
}
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_SPACE)
{
draw = true;
}
}
}
int main()
{
if(draw){
drawImage();
}
//DO SOME ERROR CHECKING
}
相关文章:
- 从Q_INVOKABLE功能或插槽中更改QQuick图像源
- 英特尔 IPP 图像大小调整功能是否关心 alpha 值的位置
- 具有SPI_SETDESKWALLPAPER功能的程序仅在尝试使用C++将其更改为图像时将桌面背景更改为黑色
- 将图像从Python包装器传递到C 功能
- 将打开的CV的重映射功能与类型CV_8SC1的源图像一起使用
- 使用更新功能扩展QML图像类型
- 将功能应用于图像的每个像素
- 在不介绍图像之后,如何找到功能的新位置
- OpenCV 中的重映射功能如何用于不失真的图像
- 使用 FLTK & C++:制作适合定义帧内图像的功能
- 如何从图像中提取FAST功能
- 图像加载功能不工作
- opencv/ c++:将保存的图像放置在具有面部识别功能的网络摄像头流上
- 绘制图像的功能
- 如何在MFC功能包中动态添加带有图像的菜单项
- 下面的图像处理功能是如何工作的
- 图像写入功能未执行
- " cvWriteFrame "使用垫子 - 图像类型的等效功能是什么?
- 使用OpenGL固定功能旋转和平移2D图像
- OpenCV读取功能无法读取图像