संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
टच इनपुट इवेंट मैनेज करने के लिए, कलेक्शन को पढ़ें
motionEvents है. ये
इसमें ऐसे इवेंट शामिल होने चाहिए जो पिछली बार इन कलेक्शन को मिटाने के बाद हुए हों.
शामिल इवेंट की संख्या motionEventsCount में सेव की जाती है.
अपने गेम लूप में, हर इवेंट को दोहराएं और मैनेज करें. इस उदाहरण में,
यह कोड motionEvents को इटरेट करता है और उन्हें 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);}
काम पूरा हो जाने के बाद, उन इवेंट की सूची को हटाना न भूलें जो आपके पास हैं
हैंडल किया जाने वाला:
android_app_clear_motion_events(mApp);
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया."],[],[],null,["# Add touch support\n\nTo handle touch input events, read the array\n[`motionEvents`](/reference/android/view/MotionEvent) in your game loop. These\ncontain events that have happened since the last time these arrays were cleared.\nThe number of events contained is stored in `motionEventsCount`.\n| **Note:** Prior to the addition of `GameActivity`, the `AInputQueue* inputQueue` field was used to handle input events. With `GameActivity`, this field has been removed from the `android_app` and no longer used for handling input events.\n\n1. Iterate and handle each event in your game loop. In this example, the\n following code iterates `motionEvents` and handles them via `handle_event`:\n\n for(size_t i = 0; i \u003c mApp-\u003emotionEventsCount; ++i) {\n GameActivityMotionEvent* motionEvent = mApp-\u003emotionEvents[i];\n\n int action = motionEvent-\u003eaction;\n int actionMasked = action & AMOTION_EVENT_ACTION_MASK;\n int ptrIndex = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) \u003e\u003e\n AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;\n\n struct CookedEvent ev;\n memset(&ev, 0, sizeof(ev));\n\n if (actionMasked == AMOTION_EVENT_ACTION_DOWN ||\n actionMasked == AMOTION_EVENT_ACTION_POINTER_DOWN) {\n ev.type = COOKED_EVENT_TYPE_POINTER_DOWN;\n } else if (actionMasked == AMOTION_EVENT_ACTION_UP ||\n actionMasked == AMOTION_EVENT_ACTION_POINTER_UP) {\n ev.type = COOKED_EVENT_TYPE_POINTER_UP;\n } else {\n ev.type = COOKED_EVENT_TYPE_POINTER_MOVE;\n }\n\n ev.motionPointerId = motionEvent-\u003epointers[ptrIndex].id;\n ev.motionIsOnScreen = motionEvent-\u003esource == AINPUT_SOURCE_TOUCHSCREEN;\n ev.motionX = GameActivityPointerInfo_getX(\n &motionEvent-\u003epointers[ptrIndex]);\n ev.motionY = GameActivityPointerInfo_getY(\n &motionEvent-\u003epointers[ptrIndex]);\n\n if (ev.motionIsOnScreen) {\n // Use screen size as the motion range.\n ev.motionMinX = 0.0f;\n ev.motionMaxX = SceneManager::GetInstance()-\u003eGetScreenWidth();\n ev.motionMinY = 0.0f;\n ev.motionMaxY = SceneManager::GetInstance()-\u003eGetScreenHeight();\n }\n\n handle_event(&ev);\n }\n\n2. When you are done, remember to clear the queue of events that you have just\n handled:\n\n android_app_clear_motion_events(mApp);"]]