באופן כללי, מומלץ להתקשר אל SwappyGL_init() מוקדם ככל האפשר במהלך רצף ההפעלה של המנוע, ומומלץ להתקשר אל SwappyGL_destroy() כשהמשחק יוצא. אין צורך לקרוא לשיטות האלה בשום זמן אחר.
הגדרת מרווח ההחלפה ותקופת הרענון
אפשר להשתמש בפונקציות הבאות כדי להגדיר מופע של Android Frame Pacing:
כשמתקשרים ל-SwappyGL_setSwapIntervalNS(), מעבירים את משך הזמן שבו צריך להציג פריים. ברוב המקרים, אפשר להשתמש באחד מהקבועים הבאים:
SWAPPY_SWAP_60FPS, SWAPPY_SWAP_30FPS או SWAPPY_SWAP_20FPS.
באופן כללי, כדאי להפעיל את השיטות האלה ישירות אחרי הפעלה של SwappyGL_init(). עם זאת, יכול להיות שתצטרכו להפעיל את השיטות האלה גם בזמנים אחרים במהלך ההרצה של המשחק.
הגדרת ANativeWindow
Swappy צריך את שם המשתמש של ANativeWindow כדי לבצע פעולה ספציפית ל-ANativeWindow, כמו התקשרות אל ANativeWindow_setFrameRate().
Call
SwappyGL_setWindow()
כשמשטח התצוגה ב-Android משתנה ויש לכם נקודת אחיזה חדשה של ANativeWindow (דוגמה אפשר לראות בBouncyball sample).
מצבים אוטומטיים
ב-Android, התכונה 'התאמת קצב הפריימים' משנה את משך ההחלפה ואת מצב צינור העיבוד על סמך משך הזמן הממוצע של הפריימים הקודמים. אפשר לשלוט בהתנהגות הזו באמצעות הפונקציות הבאות:
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-26 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-26 (שעון UTC)."],[],[],null,["Use the following functions to use Android Frame Pacing with a rendering engine\nbased on the OpenGL ES API.\n\nInitialize and destroy\n\nUse the following functions to initialize and destroy an instance of Android\nFrame Pacing, respectively:\n\n- [`void SwappyGL_init(JNIEnv *env, jobject jactivity);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#group__swappy_g_l_1gad9a8392c399ae9b87a7bfe3f14678019)\n- [`void SwappyGL_destroy();`](/games/sdk/reference/frame-pacing/group/swappy-g-l#group__swappy_g_l_1gaa8c4eac2519c1c0bede3e54d848ecd4c)\n\nIn general, you should call `SwappyGL_init()` as early as possible during the\nengine startup sequence, and you should call `SwappyGL_destroy()` when the game\nis exiting. You shouldn't need to call these methods at any other time.\n\nConfigure swap interval and refresh period\n\nUse the following functions to configure an instance of Android Frame Pacing:\n\n- [`void SwappyGL_setSwapIntervalNS(uint64_t swap_ns);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setswapintervalns)\n- [`void SwappyGL_setFenceTimeoutNS(uint64_t fence_timeout_ns);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setfencetimeoutns)\n- [`void SwappyGL_setUseAffinity(bool tf);`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setuseaffinity)\n\n| **Note:** Basic integrations usually don't require you to call `SwappyGL_setFenceTimeoutNS()` and `SwappyGL_setUseAffinity()`.\n\nWhen calling `SwappyGL_setSwapIntervalNS()`, pass in the duration that a frame\nshould be presented. In most cases, you can use one of the following constants:\n`SWAPPY_SWAP_60FPS`, `SWAPPY_SWAP_30FPS`, or `SWAPPY_SWAP_20FPS`.\n\nIn general, you should call these methods directly after a call to\n`SwappyGL_init()`. However, you might also need to call these methods at other\ntimes during your game's execution.\n\nSetting the ANativeWindow\n\nSwappy needs the handle of `ANativeWindow` in order to perform\n`ANativeWindow`-specific operation, such as calling\n[`ANativeWindow_setFrameRate()`](/ndk/reference/group/a-native-window#anativewindow_setframerate).\nCall\n[`SwappyGL_setWindow()`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_setwindow)\nwhen your Android display surface has changed and you have a new `ANativeWindow`\nhandle (see the [Bouncyball sample](https://android.googlesource.com/platform/frameworks/opt/gamesdk/+/refs/heads/master/samples/bouncyball) for an example).\n\nAuto Modes\n\nAndroid Frame Pacing adjusts the swap duration and pipeline mode based on the\naverage duration of previous frames. You can control this behavior with the\nfollowing functions:\n\n- [`void SwappyGL_setAutoSwapInterval(bool enabled);`](/games/sdk/reference/frame-pacing/group/swappy-g-l-extra#swappygl_setautoswapinterval)\n- [`void SwappyGL_setMaxAutoSwapIntervalNS(uint64_t max_swap_ns);`](/games/sdk/reference/frame-pacing/group/swappy-g-l-extra#swappygl_setmaxautoswapintervalns)\n- [`void SwappyGL_setAutoPipelineMode(bool enabled);`](/games/sdk/reference/frame-pacing/group/swappy-g-l-extra#swappygl_setautopipelinemode)\n\nPerform per-frame swap\n\nDuring each rendering frame, call\n[`bool SwappyGL_swap(EGLDisplay display, EGLSurface surface)`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_swap).\nThis method wraps the `eglSwapBuffers()` method from Open GL ES, so you should\nreplace all instances of `eglSwapBuffers()` in your game with `SwappyGL_swap()`.\n\nUtility functions\n\nThe following method checks whether Android Frame Pacing is enabled:\n\n- [`bool SwappyGL_isEnabled();`](/games/sdk/reference/frame-pacing/group/swappy-g-l#swappygl_isenabled)\n\nIt's possible that an instance of Android Frame Pacing isn't able to initialize\nitself for any of the following reasons:\n\n- The necessary EGL functions are missing on the device.\n- The system has set the `swappy.disable` property.\n\nIn either of these situations, `SwappyGL_isEnabled()` returns `false`, and it's\nbest for you to implement an alternative frame-pacing strategy.\n| **Note:** Even if `SwappyGL_isEnabled()` returns `false`, the `SwappyGL_swap()` function still invokes `eglSwapBuffers()`."]]