Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Google Sign-in API'sinin desteğinin sonlandırılmasının ardından, 2026'da Games v1 SDK'sını kaldırıyoruz. Şubat 2025'ten sonra, games v1 SDK'sına yeni entegre edilmiş oyunları Google Play'de yayınlayamazsınız. Bunun yerine games v2 SDK'sını kullanmanızı öneririz.
Önceki oyunların v1 entegrasyonlarına sahip mevcut oyunlar birkaç yıl boyunca çalışmaya devam edecek olsa da Haziran 2025'ten itibaren v2'ye geçiş yapmanızı öneririz.
Bu kılavuz, Play Games Hizmetleri v1 SDK'sının kullanımıyla ilgilidir. Play Games Hizmetleri v2 için C++ SDK'sı henüz kullanıma sunulmamıştır.
Google Play Oyun Hizmetleri C++ SDK'sı, Google Play Oyun Hizmetleri ile kullanılmak üzere bir C++ API'si sağlar ve oyunlarında mevcut bir C++ uygulaması olan geliştiriciler için tasarlanmıştır.
SDK şu anda aşağıdaki hizmetleri uygulamaktadır:
Yetkilendirme
Başarılar
Skor tabloları
Etkinlikler
Kaydedilmiş Oyunlar
Yakındaki Bağlantılar (yalnızca Android)
Oyuncu İstatistikleri
Kavramlar
SDK'yı kullanmak için genel hatlarıyla aşağıdaki adımları uygulayın:
Android için bir platform yapılandırması oluşturun.
GameServices nesnesi yapılandırmak ve oluşturmak için GameServices::Builder kullanın. GameServices nesnesi otomatik olarak oturum açmayı dener ve sonucu bir OnAuthActionFinished() geri çağırma işlevi aracılığıyla döndürür. Geri çağırma işlevi tarafından döndürülen sonucu not edin. Otomatik oturum açma denemesi başarısız olursa kullanıcıların oturum açmasına olanak tanıyan bir düğme gösterebilirsiniz.
OnAuthActionFinished() sonucunu aldıktan sonra, Play Games hizmetleri çağrıları yapmak için GameServices nesnesini ve alt yöneticilerini kullanabilirsiniz. Örneğin:
Oturum açma (yetkilendirme başarısız olduktan sonra): StartAuthorizationUI()
Yerleşik kullanıcı arayüzünü kullanarak başarıları gösterme: Achievements().ShowAllUI()
Yüksek puan gönderin: Leaderboards().SubmitScore()
Oturumu kapat: SignOut()
GameServices nesnesini kullanmayı tamamladığınızda sıfırlayın veya yok edin.
Daha ayrıntılı düzeyde:
Platform yapılandırmasını başlatma: Bu, platforma özgü başlatma bilgilerini içeren bir nesnedir. Android'de platform yapılandırması, Java sanal makinesini ve mevcut Activity'ye işaret eden bir işaretçi içerir:
// In android_main(), create a platform configuration// and bind the object activity.// Alternately, attach the activity in JNI_Onload().gpg::AndroidPlatformConfigurationplatform_configuration;platform_configuration.SetActivity(state->activity->clazz);
Bir GameServices nesnesi oluşturun: Bu nesne, Google Play Oyun Hizmetleri işlevinin ana giriş noktasıdır. GameServices örnekleri, GameServices::Builder ile oluşturulur.
Çoğu uygulamada, belirli bir GameServices nesnesi C ortamınız var olduğu sürece devam eder. Android Activity'unuz durakladığında ve devam ettiğinde nesneyi yeniden başlatmanız gerekmez.
// Creates a GameServices object that has lambda callbacks.game_services_=gpg::GameServices::Builder().SetDefaultOnLog(gpg::LogLevel::VERBOSE).SetOnAuthActionStarted([started_callback](gpg::AuthOperationop){is_auth_in_progress_=true;started_callback(op);}).SetOnAuthActionFinished([finished_callback](gpg::AuthOperationop,gpg::AuthStatusstatus){LOGI("Sign in finished with a result of %d",status);is_auth_in_progress_=false;finished_callback(op,status);}).Create(pc);
GameServices nesnenizi yönetmek için Yönetici sınıflarını kullanın. Yöneticilere bir GameServices örneğinden ve grupla ilgili işlevlerden birlikte erişilir. Başarı ve Liderlik Tablosu Yöneticileri bu tür rollere örnek gösterilebilir. Kullanıcı tarafından görülebilen bir durum içermezler. Yöneticiler referansla döndürülür ve yaşam döngüleri, onları içeren GameServices örneği tarafından kontrol edilir. Müşterinizin yönetici referansını hiçbir zaman elinde tutmaması gerekir. Bunun yerine, müşteriniz GameServices örneğini elinde tutmalıdır.
Yöneticiler, verileri sabit değer türü nesneleri aracılığıyla döndürür. Bu değerler, sorgunun yapıldığı anda temel verilerin tutarlı bir görünümünü yansıtır.
// Submit a high scoregame_services_->Leaderboards().SubmitScore(leaderboard_id,score);// Show the default Achievements UIgame_services_->Achievements().ShowAllUI();
GameServices nesnesini kullanmayı bitirdiğinizde, sahibi olan unique_ptr üzerinde reset()'ı çağırarak veya kapsam dışında kaldığında unique_ptr'nin otomatik olarak yok etmesine izin vererek temizlik yapın.
Konu dizisi modeli
Aksi belirtilmedikçe tüm GameServices ve Yönetici yöntemleri, iş parçacığı güvenli ve eşzamansız uygulamalara sahiptir. Bu işlevler, harici kilitleme olmadan herhangi bir iş parçacığında çağrılabilir ve çağrılma sıralarıyla tutarlı bir sırada yürütülür.
Erişim yöntemleri (durumu okuyan yöntemler) iki ana varyantta bulunur. İlk yöntem türü (FetchProperty() gibi adlara sahip), sonuçlarını sağlanan bir geri çağırma işlevine asenkron olarak sağlar. İkinci yöntem türü (FetchPropertyBlocking() gibi adlara sahip) ise sonuçlarını çağıran iş parçacığına senkron olarak döndürür.
Tüm kullanıcı geri çağırma işlemleri, özel bir geri çağırma mesaj dizisinde çağrılır. Bu iş parçacığı, "ana iş parçacığı" veya "kullanıcı arayüzü iş parçacığı" gibi platform kavramlarından farklı olabilir. Ayrıca, kullanıcı geri çağırmalarının hızlı bir şekilde yürütülmesini sağlamaya çalışmalısınız. Durdurulan bir geri çağırma mesajı kullanıcı tarafından görülebilen sorunlara (ör. oturum kapatma isteğinin gecikmeli olarak tamamlanması) neden olabilir.
Daha fazla bilgi için Google Play Oyun Hizmetleri C++ SDK'sında bulunan sınıf dokümanlarını okumayı ve SDK'nın nasıl kullanıldığını gösteren örneklere göz atmayı unutmayın.
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-26 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-07-26 UTC."],[],[],null,["# Play Games Services for C++\n\nFollowing the deprecation of the\n[Google Sign-In](https://android-developers.googleblog.com/2024/09/streamlining-android-authentication-credential-manager-replaces-legacy-apis.html)\nAPI, we are removing the games v1 SDK in 2026. After February 2025, you will be unable to publish\ntitles that are newly integrated with games v1 SDK, on Google Play. We recommend that you use the\ngames v2 SDK instead. \n\nWhile existing titles with the previous games v1 integrations continue to function for a\ncouple of years, you are encouraged to\n[migrate to v2](/games/pgs/android/migrate-to-v2)\nstarting June 2025. \n\nThis guide is for using the Play Games Services v1 SDK. The C++ SDK for\nPlay Games Services v2 is not yet available.\n\nThe Google Play games Services C++ SDK provides a C++ API for use with Google Play Game\nservices, and is meant for developers who have an existing C++ implementation\nof their game.\n\nCurrently, the SDK implements the following services:\n\n- Authorization\n- Achievements\n- Leaderboards\n- Events\n- Saved Games\n- Nearby Connections (Android only)\n- Player Statistics\n\nConcepts\n--------\n\nAt a high level, you use the SDK by following these steps:\n\n1. Set up a platform configuration for Android.\n2. Use a `GameServices::Builder` to configure and construct a `GameServices` object. The `GameServices` object automatically attempts to sign in, and returns the result via an `OnAuthActionFinished()` callback. Take note of the result returned by the callback. If the automatic sign-in attempt failed, you can display a button to let users sign in.\n3. After receiving the `OnAuthActionFinished()` result, you can use the\n `GameServices` object and its child Managers to make Play Games services calls,\n including:\n\n - Sign in (after authorization fails): `StartAuthorizationUI()`\n - Unlock achievements: `Achievements().Unlock()`\n - Show achievements using built-in UI: `Achievements().ShowAllUI()`\n - Submit a high score: `Leaderboards().SubmitScore()`\n - Sign out: `SignOut()`\n4. When you are done using the `GameServices` object, reset or destroy it.\n\nAt a more detailed level:\n\n1. Initialize a platform configuration: This is an object that contains\n platform-specific initialization information. On Android, the platform configuration contains the\n Java VM and a pointer to the current `Activity`:\n\n // In android_main(), create a platform configuration\n // and bind the object activity.\n // Alternately, attach the activity in JNI_Onload().\n gpg::AndroidPlatformConfiguration platform_configuration;\n platform_configuration.SetActivity(state-\u003eactivity-\u003eclazz);\n\n2. Construct a `GameServices` object: This object is the main entry point for\n Google Play games Services functionality. `GameServices` instances are created\n with `GameServices::Builder`.\n\n In most implementations, a given `GameServices` object will persist as long as\n your C environment does; you do not need to reinitialize it when your\n Android `Activity` pauses and resumes. \n\n // Creates a GameServices object that has lambda callbacks.\n game_services_ = gpg::GameServices::Builder()\n .SetDefaultOnLog(gpg::LogLevel::VERBOSE)\n .SetOnAuthActionStarted([started_callback](gpg::AuthOperation op) {\n is_auth_in_progress_ = true;\n started_callback(op);\n })\n .SetOnAuthActionFinished([finished_callback](gpg::AuthOperation op,\n gpg::AuthStatus status) {\n LOGI(\"Sign in finished with a result of %d\", status);\n is_auth_in_progress_ = false;\n finished_callback(op, status);\n })\n .Create(pc);\n\n3. Use the Manager classes to manage your `GameServices` object. Managers are accessed from a `GameServices` instance and group related functionality\n together. Examples of these\n include the Achievement and Leaderboard Managers. They contain no user-visible\n state themselves. Managers are returned by reference, and the containing\n `GameServices` instance controls their lifecycle. Your client should never hold\n onto a Manager reference. Instead, your client should hold on to the\n `GameServices` instance.\n\n Managers return data via immutable value type objects. These values\n reflect a consistent view of the underlying data at the point in time when\n the query was made. \n\n // Submit a high score\n game_services_-\u003eLeaderboards().SubmitScore(leaderboard_id, score);\n\n // Show the default Achievements UI\n game_services_-\u003eAchievements().ShowAllUI();\n\n4. When you are finished using the `GameServices` object, clean up by\n calling `reset()` on the `unique_ptr` that owns it, or by letting the\n `unique_ptr` automatically destroy it when going out of scope.\n\nThreading model\n---------------\n\nUnless otherwise noted, all `GameServices` and Manager methods have\nthread-safe, asynchronous implementations. They can be called on any thread without\nexternal locking, and will execute in an order consistent with their invocation\norder.\n\nAccessor methods (those that read state) come in two major variants. The first\ntype of method (with names like `FetchProperty()`) asynchronously supplies its results\nto a provided callback; the second (with names like\n`FetchPropertyBlocking()`) synchronously returns its results to the calling\nthread. \n\n // Blocking callback\n gpg::AchievementManager::FetchAllResponse fetchResponse =\n game_services_-\u003eAchievements().FetchAllBlocking(std::chrono::milliseconds(1000));\n\n // Non-blocking callback\n game_services_-\u003eAchievements().FetchAll(gpg::DataSource::CACHE_OR_NETWORK,\n [] (gpg::AchievementManager::FetchAllResponse response) {\n LogI(\"Achievement response status: %d\", response.status);});\n\nAll user callbacks are invoked on a dedicated callback thread. This thread is\npotentially distinct from any platform concept of a \"main thread\" or \"UI\nthread\". You should also try to ensure that user callbacks execute quickly; a stalled callback thread\nmay cause user-visible issues (for example, delayed completion of a sign-out\nrequest).\n\nPlatform-specific information\n-----------------------------\n\nTo get started using the Play Games C++ SDK on Android, continue to the\n[quickstart guide](/games/pgs/v1/cpp/quickstart).\n\nFurther reading\n---------------\n\nBe sure to read the class documentation that comes in the Google Play Game\nservices C++ SDK for further details, and check out the\n[samples](https://github.com/playgameservices/) that demonstrate how to use the SDK.\n\nIf your game uses a backend server, see\n[Enabling Server-Side Access to Google Play Games Services](/games/pgs/v1/android/server-access)."]]