Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Để xử lý các sự kiện nhập bằng cách chạm, hãy đọc mảng motionEvents trong vòng lặp trò chơi. Các mảng này chứa những sự kiện đã xảy ra kể từ lần xoá mảng gần đây nhất.
Số lượng sự kiện nằm trong mảng được lưu trữ tại motionEventsCount.
Lặp và xử lý từng sự kiện trong vòng lặp trò chơi. Trong ví dụ này, mã sau đây sẽ lặp lại motionEvents và xử lý các sự kiện đó qua handle_event:
for(size_ti=0;i < mApp->motionEventsCount;++i){GameActivityMotionEvent*motionEvent=mApp->motionEvents[i];intaction=motionEvent->action;intactionMasked=action & AMOTION_EVENT_ACTION_MASK;intptrIndex=(action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)>>
AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;structCookedEventev;memset(&ev,0,sizeof(ev));if(actionMasked==AMOTION_EVENT_ACTION_DOWN||actionMasked==AMOTION_EVENT_ACTION_POINTER_DOWN){ev.type=COOKED_EVENT_TYPE_POINTER_DOWN;}elseif(actionMasked==AMOTION_EVENT_ACTION_UP||actionMasked==AMOTION_EVENT_ACTION_POINTER_UP){ev.type=COOKED_EVENT_TYPE_POINTER_UP;}else{ev.type=COOKED_EVENT_TYPE_POINTER_MOVE;}ev.motionPointerId=motionEvent->pointers[ptrIndex].id;ev.motionIsOnScreen=motionEvent->source==AINPUT_SOURCE_TOUCHSCREEN;ev.motionX=GameActivityPointerInfo_getX(&motionEvent->pointers[ptrIndex]);ev.motionY=GameActivityPointerInfo_getY(&motionEvent->pointers[ptrIndex]);if(ev.motionIsOnScreen){// Use screen size as the motion range.ev.motionMinX=0.0f;ev.motionMaxX=SceneManager::GetInstance()->GetScreenWidth();ev.motionMinY=0.0f;ev.motionMaxY=SceneManager::GetInstance()->GetScreenHeight();}handle_event(&ev);}
Khi thực hiện xong, nhớ xoá hàng đợi các sự kiện mà bạn vừa xử lý:
android_app_clear_motion_events(mApp);
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2024-08-22 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Thiếu thông tin tôi cần"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Quá phức tạp/quá nhiều bước"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Đã lỗi thời"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Vấn đề về bản dịch"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Vấn đề về mẫu/mã"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Khác"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Dễ hiểu"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Giúp tôi giải quyết được vấn đề"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Khác"
}]
{"lastModified": "C\u1eadp nh\u1eadt l\u1ea7n g\u1ea7n \u0111\u00e2y nh\u1ea5t: 2024-08-22 UTC."}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2024-08-22 UTC."]]