도움이 필요합니다. 블랙 베리 플레이 북 게임을 만들지 만, 멀티 터치 이벤트 처리에 문제가 있습니다. 나는 CInput 클래스를 터치 이벤트를 처리하는 예제에서 가져온 것으로 사용한다. (모든 터치는 오른쪽 좌표와 터치 카운트를 가지고있다.) 그러나 같은 터치 패드에서 2 터치와 터치를 동시에 할 때 CInput은 1 이벤트를 릴리스하지 않는다. 접촉. 시뮬레이터 나 작서에서이 버그를 볼 수 있습니다. 터치로 작업하기위한이 파트 코드. 어떻게 고칠 수 있니? 누군가가 도울 수 있으면 고마워. 죄송합니다 나쁜 영어마멀레이드 SDK 멀티 터치
void touchUpdate()
{
g_Input.Update();
printf("count %d\n", 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();
}
나는 놀이터 버그라고 생각하지 않습니다. 나는 이미 마멀레이드를 사용하여 작곡가에서 멀티 터치를 사용했습니다. 다른 장치 (아마 Android)에서 확인하십시오. – noob
이것은 에뮬레이터에서도 발생할 수 있습니다. 이 버그를 더 어렵게 재생하십시오. – art65536
즉, 코드에 약간의 문제가 있음을 의미합니다. 내가 검토해볼 께. – noob