Marmalade SDK Multitouch
Marmalade SDK Multitouch
我需要帮助。我做游戏黑莓playbook,但我有麻烦的多点触控事件处理。我使用从例子中获取的CInput类来处理触摸事件,它工作(所有的触摸都有正确的坐标和触摸计数正确),但是当在同一时间进行2次触摸和释放触摸时,CInput没有释放1个事件,就像我没有释放触摸一样出错。我可以在模拟器或剧本中看到这个bug。本部分适用于接触工作。我怎样才能修好它?如果有人能帮忙,谢谢。抱歉我的英语不好
void touchUpdate()
{
g_Input.Update();
printf("count %dn", g_Input.getTouchCount());
if (g_Input.getTouchCount() != 0)
{
CTouch* touch;
if (g_Input.isMultiTouch())
{
for (int i = 0; i < g_Input.getTouchCount(); i++)
{
touch = g_Input.getTouch(i);
if (touch != NULL)
{
if (!touch->active)
{
touch->x = -1;
touch->y = -1;
continue;
}
else if (checkButton(&btnAction, touch))
{
if (menu->isGameEnabled())
{
currentGame->eventAction();
}
else
{
currentGame = menu->eventAction();
}
continue;
}
else if (checkButton(&btnUp, touch))
{
if (menu->isGameEnabled())
{
currentGame->eventUp();
}
else
{
menu->eventUp();
}
continue;
}
else if (checkButton(&btnDown, touch))
{
if (menu->isGameEnabled())
{
currentGame->eventDown();
}
else
{
menu->eventDown();
}
continue;
}
else if (checkButton(&btnLeft, touch))
{
if (menu->isGameEnabled())
{
currentGame->eventLeft();
}
else
{
menu->eventLeft();
}
continue;
}
else if (checkButton(&btnRight, touch))
{
if (menu->isGameEnabled())
{
currentGame->eventRight();
}
else
{
menu->eventRight();
}
continue;
}
else if (checkButton(&btnPause, touch))
{
if (menu->isGameEnabled())
{
currentGame->eventPause();
}
continue;
}
else if (checkButton(&btnSound, touch))
{
// off/on sound
continue;
}
else if (checkButton(&btnMenu, touch))
{
// force drop to menu
if (menu->isGameEnabled())
{
currentGame->eventMenu();
}
continue;
}
}
}
}
}
}
currentGame->eventMenu(), currentGame->eventUp()等…它只是在游戏逻辑或主菜单中起作用。这个函数必须在按下按钮时调用。
struct roundButton
{
int x, y;
int radius;
bool pressed;
};
bool checkButton(roundButton *button, CTouch *touch)
{
if ((button->x - touch->x) * (button->x - touch->x) + (button->y - touch->y) * (button->y - touch->y) <= button->radius * button->radius)
{
button->pressed = true;
return true;
}
return false;
}
这是我检查按钮是否按下的方式
#ifndef SRC_INPUT_H_
#define SRC_INPUT_H_
#include "IwGeom.h"
#include "s3ePointer.h"
#define MAX_TOUCHES 2
struct CTouch
{
public:
int x, y;
bool active;
int id;
};
class CInput
{
private:
bool Available; // true if a pointer is present
bool IsMultiTouch; // true if multitouch is enabled
CTouch Touches[MAX_TOUCHES]; // List of potential touches
public:
bool isAvailable() const { return Available; } // Returns availability of the pointer
bool isMultiTouch() const { return IsMultiTouch; } // Returns multitouch capability
CTouch* getTouchByID(int id); // returns the touch identified by its id
CTouch* getTouch(int index) { return &Touches[index]; } // Gets a specific touch
CTouch* findTouch(int id); // Finds a specific touch by its id
int getTouchCount() const; // Get number of touches this frame
public:
bool Init(); // Initialises the input system (returns true if pointer is supported)
void Release(); // Releases data used by the input system
void Update(); // Updates the input system, called every frame
};
extern CInput g_Input;
#endif // SRC_INPUT_H_
CInput类
#include "input.h"
CInput g_Input;
void HandleMultiTouchButtonCB(s3ePointerTouchEvent* event)
{
CTouch* touch = g_Input.findTouch(event->m_TouchID);
if (touch != NULL)
{
touch->active = event->m_Pressed != 0;
touch->x = event->m_x;
touch->y = event->m_y;
}
}
void HandleMultiTouchMotionCB(s3ePointerTouchMotionEvent* event)
{
CTouch* touch = g_Input.findTouch(event->m_TouchID);
if (touch != NULL)
{
touch->x = event->m_x;
touch->y = event->m_y;
}
}
void HandleSingleTouchButtonCB(s3ePointerEvent* event)
{
CTouch* touch = g_Input.getTouch(0);
touch->active = event->m_Pressed != 0;
touch->x = event->m_x;
touch->y = event->m_y;
}
void HandleSingleTouchMotionCB(s3ePointerMotionEvent* event)
{
CTouch* touch = g_Input.getTouch(0);
touch->x = event->m_x;
touch->y = event->m_y;
}
CTouch* CInput::findTouch(int id)
{
if (!Available)
return NULL;
for (int t = 0; t < MAX_TOUCHES; t++)
{
if (Touches[t].id == id)
return &Touches[t];
if (!Touches[t].active)
{
Touches[t].id = id;
return &Touches[t];
}
}
return NULL;
}
CTouch* CInput::getTouchByID(int id)
{
for (int t = 0; t < MAX_TOUCHES; t++)
{
if (Touches[t].active && Touches[t].id == id)
return &Touches[t];
}
return NULL;
}
int CInput::getTouchCount() const
{
if (!Available)
return 0;
int count = 0;
for (int t = 0; t < MAX_TOUCHES; t++)
{
if (Touches[t].active)
count++;
}
return count;
}
bool CInput::Init()
{
Available = s3ePointerGetInt(S3E_POINTER_AVAILABLE) ? true : false;
if (!Available)
return false;
for (int t = 0; t < MAX_TOUCHES; t++)
{
Touches[t].active = false;
Touches[t].id = 0;
}
IsMultiTouch = s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE) ? true : false;
if (IsMultiTouch)
{
s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)HandleMultiTouchButtonCB, NULL);
s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)HandleMultiTouchMotionCB, NULL);
}
else
{
s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)HandleSingleTouchButtonCB, NULL);
s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)HandleSingleTouchMotionCB, NULL);
}
return true;
}
void CInput::Release()
{
if (Available)
{
if (IsMultiTouch)
{
s3ePointerUnRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)HandleMultiTouchButtonCB);
s3ePointerUnRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)HandleMultiTouchMotionCB);
}
else
{
s3ePointerUnRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)HandleSingleTouchButtonCB);
s3ePointerUnRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)HandleSingleTouchMotionCB);
}
}
}
void CInput::Update()
{
if (Available)
s3ePointerUpdate();
}
我找到bug了。函数findTouch甚至可以返回非活动的触摸。所以fix看起来像
CTouch* CInput::findTouch(int id)
{
if (!Available)
return NULL;
for (int t = 0; t < MAX_TOUCHES; t++)
{
if (Touches[t].id == id)
return &Touches[t];
}
for (int t = 0; t < MAX_TOUCHES; t++)
{
if (!Touches[t].active)
{
Touches[t].id = id;
return &Touches[t];
}
}
return NULL;
}
相关文章:
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- Vulkan SDK 版本 1.1.85.0 在 Kubuntu 18.10 上链接
- 升级到 Windows 10 版本 1809 SDK 后,我无法编译使用 C++/WinRT 的项目
- 在设计 SDK 时,我是否应该在 C++ 头文件中完全隐藏内部类?
- Eventloop 卡住:NAO C++ SDK OnFaceDetection 示例
- 构建失败错误:无法使用 qibuild 构建C++ SDK Helloworld
- Microsoft C++ 用于图形 API 的 Rest SDK
- 如何检索 Steamwork SDK 的当前版本
- 佳能SDK无法从相机下载图片
- 如何使用 CPP REST SDK 实现 CAS(中央认证服务)?
- 在为 iOS 构建 aws-sdk-cpp 时,cmake 上的 CXX 编译器错误已损坏
- 关于 API 文档和设备操作 在助手-sdk-cpp 上
- C++标准视窗 SDK 文件中的编译错误
- DLL:当 SDK 头文件不使用 __declspec(dllexport) 时,我可以使用它吗
- 将 aws-iot-device-sdk-cpp-v2 与 CMake 结合使用
- "byte":使用Crypto++和Windows SDK时出现不明确的符号错误
- FBX SDK 在预期 3 个顶点时返回 4 个顶点
- Qt & Firebase C++ SDK 在 iOS 上的链接问题
- Yocto-bitbake与SDK系统根冲突
- Marmalade SDK Multitouch