به طور کلی، شما باید SwappyGL_init() هر چه زودتر در طول دنباله راه اندازی موتور فراخوانی کنید، و باید SwappyGL_destroy() هنگام خروج از بازی فراخوانی کنید. شما نباید در هر زمان دیگری نیازی به فراخوانی این روش ها داشته باشید.
پیکربندی فاصله مبادله و دوره تجدید
برای پیکربندی یک نمونه از Android Frame Pacing از عملکردهای زیر استفاده کنید:
هنگام فراخوانی SwappyGL_setSwapIntervalNS() ، مدت زمانی که یک فریم باید ارائه شود را بگذرانید. در بیشتر موارد، میتوانید از یکی از ثابتهای زیر استفاده کنید: SWAPPY_SWAP_60FPS ، SWAPPY_SWAP_30FPS ، یا SWAPPY_SWAP_20FPS .
به طور کلی، شما باید این متدها را مستقیماً پس از تماس با SwappyGL_init() فراخوانی کنید. با این حال، ممکن است لازم باشد این روش ها را در زمان های دیگر در طول اجرای بازی خود فراخوانی کنید.
تنظیم ANativeWindow
Swappy برای انجام عملیات خاص ANativeWindow ، مانند فراخوانی ANativeWindow_setFrameRate() به دسته ANativeWindow نیاز دارد. زمانی که سطح صفحه نمایش اندروید شما تغییر کرد و یک دسته ANativeWindow جدید دارید، SwappyGL_setWindow() را فراخوانی کنید (برای نمونه به نمونه Bouncyball مراجعه کنید).
حالت های خودکار
Android Frame Pacing مدت زمان تعویض و حالت خط لوله را بر اساس میانگین مدت فریم های قبلی تنظیم می کند. شما می توانید این رفتار را با توابع زیر کنترل کنید:
در طول هر فریم رندر، bool SwappyGL_swap(EGLDisplay display, EGLSurface surface) را فراخوانی کنید. این متد متد eglSwapBuffers() از Open GL ES میپیچد، بنابراین شما باید همه نمونههای eglSwapBuffers() در بازی خود با SwappyGL_swap() جایگزین کنید.
توابع سودمند
روش زیر بررسی میکند که آیا Android Frame Pacing فعال است یا خیر:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-26 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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 بهوقت ساعت هماهنگ جهانی."],[],[],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()`."]]