如何正确使用SDL_MOUSEBUTTONDOWN
How to use SDL_MOUSEBUTTONDOWN correctly?
我试图使用x和y坐标从鼠标的游戏,但我不能得到坐标。
这是我一直在阅读的事件:
typedef struct{
Uint8 type;
Uint8 button;
Uint8 state;
Uint16 x, y;
} SDL_MouseButtonEvent;
我需要这样的东西:
if(SDL_MouseButtonEvent.x >= 100)
{
//do something
}
我认为sintax是非常不同的,因为我看到了一些使用SDL_MOUSEBUTTONDOWN的例子。
编辑
我很抱歉,我知道这个问题可能不是很清楚,但是Peter的回答正是我需要的,谢谢你的时间。
快速精确:鼠标的绝对移动和相对移动分别用event.motion.x
和event.motion.xrel
代替event.mouse.x
,均为int
。
如果你想拦截一个点击在一个特定的区域首先你需要轮询事件和检查SDL_MouseButtonEvent。
while(running)
{
while(SDL_PollEvent(&event)) // check to see if an event has happened
{
switch(event.type)
{
case SDL_QUIT:
running = false;
break;
case SDL_MOUSEBUTTONDOWN: // if the event is mouse click
if(event.mouse.x >= 100) // check if it is in the desired area
{
//do something
}
}
}
}
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- SDL 窗口不会弹出
- SDL 操纵杆按钮按下/C++
- VSCode IntelliSense无法识别SDL框架的SDL_image扩展库
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- SDL 映像:无法打开映像,仅显示错误消息
- 如何在 3D OpenGL 场景上绘制 SDL 2D 矩形?
- "Undefined symbols for architecture x86_64" 在 SDL 2 (macOS) 中
- 为什么 SDL 在 Mac 上比 Linux 慢得多?
- 在 OSX 上打开 SDL 窗口时不要打开终端窗口
- SDL + OpenGL ES 2.0 使用着色器显示纹理
- SDL GPU 为什么将两个图像分成两个单独的循环更快?
- 在 cmake 中找不到 SDL 库
- SDL/C++: 如何平滑但随机地移动矩形?
- 如何与 SDL 库链接?
- 为什么我的C++代码不呈现 SDL 矩形?
- 为什么要在初始化SDL之前在SDL中声明指针
- C++/SDL 如何覆盖数组?
- 在 SDL 中水平减小静态图像进度条