Skip to content

Repository files navigation

bevy_ios_gamecenter

crates.io docs.rs discord

Bevy Plugin to provide access to iOS native GameKit (Gamecenter) from inside Bevy Apps.

Talks to GameKit directly via objc2 - no Swift package or XCode setup required.

demo

Demo from our game using this crate: zoolitaire.com

Features

TODOs

  • challenges, matchmaking

Instructions

  1. Add Rust dependency
  2. Setup Plugin

Note: Game Center still has to be enabled for your app in App Store Connect, and save games additionally require the iCloud capability.

1. Add Rust dependency

cargo add bevy_ios_gamecenter

2. Setup Plugin

Initialize Bevy Plugin:

// init right on startup
app.add_plugins(IosGamecenterPlugin::new(true));
fn bevy_system(mut gc: BevyIosGamecenter) {

    gc.authenticate()
        .on_response(|result: On<AuthenticationResult>| match result.response {
            IosGCAuthResult::IsAuthenticated => {},
            IosGCAuthResult::LoginPresented => {},
            IosGCAuthResult::Error(e) => error!("auth error: {e}"),
        });

    // here we request the player info type for the username and more
    // Note: all requests via `gc` of type `BevyIosGamecenter`
    // allow to attach an observer to listen to the response:
    gc.request_player().on_response(on_player_response);

    // update achievement progress, 100 % will complete it
    gc.achievement_progress("id".into(),100.);

    // reset all achievements
    gc.achievements_reset();

    // save a game state as a byte slice
    gc.save_game("test".into(), vec![1, 2, 3].as_slice());

    // request list of `IosGCSaveGame`
    gc.fetch_save_games().on_response(on_response);

    // based on result of above `fetch_save_games` request
    let save_game = IosGCSaveGame {..}
    gc.load_game(save_game);

    // update leaderboard score
    gc.leaderboards_score(
        "raking id".into(),
        // score
        1,
        // context
        2,
    );

}

// opening the gamecenter view has no response, so it is a plain free function
bevy_ios_gamecenter::trigger_view(view_states::LEADERBOARDS);

Our Other Crates

Bevy version support

bevy bevy_ios_gamecenter
0.19 0.7,main
0.18 0.6
0.17 0.5
0.16 0.4
0.15 0.3
0.14 0.2
0.13 0.1

License

All code in this repository is dual-licensed under either:

at your option. This means you can select the license you prefer.

Your contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Bevy Plugin and Swift Package to provide access to iOS native Gamecenter from inside Bevy

Topics

Resources

Stars

29 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages