Game-Center-iconReady to invite your friends to play your latest game? You’re in luck!

Starting in Daily Build #1172, you can develop iOS games that take full advantage of turn-based multiplayer features in Game Center.

We’ve built all these features into the ‘gameNetwork’ library so whether you have existing code or new code, it’ll be a cinch to use.

There’s a full sample available: https://github.com/coronalabs/gameNetwork-iOS-turnbased-multiplayer.

Here’s a quick tour:

To invite players, you create a match with specific player id’s:

gameNetwork.request( "createMatch",
{
    playerIDs = {"w4o98y3498hg349h", "wrighfq547hg543"},
    listener=requestCallback
})

To auto-match players, you also create a match but you specify the number of players you want to match:

gameNetwork.request( "createMatch",
{
    minPlayers = 2,
    maxPlayers = 3,
    listener=requestCallback
})

You can also mix and match, inviting some some players and then also auto match players to the same match:

gameNetwork.request( "createMatch",
{
    playerIDs = {"w4o98y3498hg349h", "wrighfq547hg543"},
    minPlayers = 2,
    maxPlayers = 3,
    listener=requestCallback
})

When the request listener is fired, the events contain a property ‘event.type’ that takes on the following values:

  • invitationReceived
  • matchEnded
  • playerTurn

Perhaps the coolest thing is that notifications that tell you it’s your turn are automatic, so you don’t need to do anything!

Happy coding!

[Update] We also plan to add support for Game Center features added to iOS 6 such as invite messages, player attributes, and player groups.

  1. Sounds good. Even though I don’t really know how to get the player Ids of the friends (is there maybe a way to get all the gamecenter friends and their corresponding ids to invite them?). Hope we’ll see someone using that feature :)

  2. @Chris
    You can get the ids of your friends with this:

    local function requestCallback(event)
    print(event.data[1].playerID)
    end

    gameNetwork.request( “loadFriends”, { listener=requestCallback } )

    Note that this only gets the ids of your friends and not their aliases. To get their aliases you have to do something like this:

    gameNetwork.request( “loadPlayers”,
    {
    playerIDs =
    {
    “G:123456789″,
    “G:1234567890″,
    “G:0123456789″
    },
    listener=requestCallback
    })

    There is an example of this in our sample code located here:
    https://github.com/coronalabs/gameNetwork-iOS-turnbased-multiplayer/blob/master/menu-scene.lua#L70

    Hope this helps and happy coding!

    • @ed69
      We did not implement inviteMessage because that is an iOS 6+ feature. Since we support iOS 5 we didn’t want to have some functionality that wasn’t available for all the iOS platforms we support.

      As for the other 2, those are not vital to implementing turn based multiplayer. This will be something we will implement in the future on a second pass.

      • @dchan – sorry, but this explanation is very very weird – how could you decide to block feature development just because it is iOS6+ ?
        iOS7 will be released soon and beta release build is already integrated in the Corona SDK!
        As Kerem also kindly pointed you – Apple already reported that more than 94% of the iOS customers are using iOS6!

        Regarding features which are “vital” or either not for the turn based multiplayer – how could you take this responsibility on you to decide which functionality should be available in my final product and which not?
        I’m paid pro Corona SDK customer and I expect to have full functionality for the turn based multiplayer support as it is stated in second sentence of this blogpost (and especially if other developers also explicitly asking about this)!
        For example, I need to have “playerGroup” option available, to be able to split players which would like to play in different game modes with each other – and this is essential for every multiplayer app today!
        How should I resolve this – any proposals? And could you please provide any reasonable argumentation why it was not implemented?

        On the other hand – If you are not able and not going to provide full support for turn based multiplayer on iOS – please ask Walter at least to fix the title of this blog post to something like “Turn-based multiplayer support only partially available” – this would be more fair and will not confuse other developers.

  3. NoobHub is a nice service which I have tried already earlier – it is definitely possible to buildup completely working multiplayer with it, but it will require to host my own server (or server farm even) to install it and to configure it, to take care about keep it up and running, to setup monitoring and load tracking and etc. – all stuff you need to have if you would like to go on with your own servers plus of course it will be not for free – it will be needed to pay for hosting and spend a lot of working time on this!

    But the point is – all this, not really needed to be done at all, as soon as full featured multiplayer services are already available from Apple side (and for very long time already) and which I (in theory) able to use absolutely for free as subscribed Apple iOS developer – BUT they are just blocked in Corona SDK implementation for unknown reason!
    This is what I’m trying to clarify here – why it is implemented only partially that in any more or less serious game it will be just not usable or looks unprofessional?

    @Walter – could you please clarify why this implementation was done in a such bad way? Could it be, that these 3 additional parameter are skipped away from integration in Corona SDK just to have another reason to proposed developers to buy more expensive product “Enterprise Edition”?

    • ed69 – thanks for the comments.

      First of all, no, we did not take out 3 parameters just to make you upgrade to Corona Enterprise. That has never been our intention with any features we do/do not implement.
      There are 2 things that happened here:

      1) The team made a call on what to prioritize given some internal deadlines and those 3 parameters were left out of the *first pass*
      2) There was a slight miscommunication with Walter, hence the “full support” headline

      We do understand your feedback. Notice that both Danny and I mention this is a *first pass*. I personally will see what we can do to include these other items ASAP.

      David

    • Okay, I’ve added an update at the bottom of the post to clarify.

      @ed69, I want to prioritize this appropriately, so can you help us understand how these iOS 6-specific GC features play a critical role in your game?

      For example, the wildly successful Letterpress (v1.4) game works uses Game Center extensively. However, it works on iOS 5, so it does not utilize any iOS 6-specific GC features.

  4. @David & @Walter – thank you a lot for clear responses!
    From my side I’m happy to help, especially if this will speedup and improve situation.
    First of all I’d like to explain why missing parameters (at least for me) making the current turn based multiplayer practically not usable.

    1. The most critical and important for me is the missing parameter “playerGroup” – it is not mandatory required in GameKit from Apple side, but it is de facto must have, as soon as there is more than one play mode in the game (and it is like that in the most of the games). For example, if we have 2 maps in the game to play it is needed to split all users on 2 groups and provide this information to the Game Center that matchmaker function will know that players in group 1 should play on the map 1 with players from group 1 and not with players from group 2 which should play on the map 2. Same use case we have also with the card/board games – for example there is many variants of the checkers game (like board size 8×8 or 10×10 and other game rules modifications) which required also correspondently to split users on the specific groups: users who select 8×8 boards cannot play with the users who select 10×10 boards, but only on the same sizes of course. Hope this is clear, here is the link to the GameKit docu from Apple: http://developer.apple.com/library/ios/documentation/GameKit/Reference/GKMatchRequest_Ref/Reference/Reference.html#//apple_ref/occ/instp/GKMatchRequest/playerGroup

    2. “playerAttributes” – also missing in current implementation, for me it is not critical right now, but for convenience it will make sense to implemented it together with the “playerGroup” property. Documentation for it is available here: http://developer.apple.com/library/ios/documentation/GameKit/Reference/GKMatchRequest_Ref/Reference/Reference.html#//apple_ref/occ/instp/GKMatchRequest/playerAttributes

    Please note – this two properties “playerGroup” and “playerAttributes” are not newly invented in iOS60 – they are actually available since iOS4.1.

    3. “inviteMessage” – this is a relative new iOS6.0 property which allows to make your custom invite text message to be displayed for the player to join the match. Of course it is possible to initiate multiplayer match without it, but this is what make your (our) apps looking more professional when they have this fine customization, but I can leave without this (and as Letterpress probably also).

    4. “maxPlayersAllowedForMatchOfType” – strictly speaking as from iOS6+ this function is must have and should be used before to set maxPlayers parameter in the matchmaking request (as required by Apple).

    Please let me know if there other questions to clarify.
    Would be also great to get clear feedback from you when these missing parameters will be integrated (or may be one by one, like playerGroup and then others, if you would like to do it like that).

  5. @David & @Walter – could you please provide an update regrading missing properties?
    Basically it should not be much work to add them to the existing implementation – as I understood it is required only to add them to the gameNetwork.request and then pass from lua to the GameKit as it is done already for parameters playerIDs, minPlayers and maxPlayers and that’s it, isn’t it?

  6. Build 1181 logs

    iOS: Add support for playerGroup, playerAttribute, inviteMessage, and maxPlayersAllowedMatch to iOS turn based multiplayer.

    Great job!!! Thank you very much for being so responsive to feedback. Have a great day.

  7. I am a programmer in training, and so far I have used Kwik to create apps, adding custom code here and there. I have read the Corona Cloud documentation, as well as the GameCenter documentation, and this document. But I still don’t understand a few things. Does one need a Corona Cloud account to implement the features described in this article? or does this happen in the GameCenter (Apple) backend? Does this require a yearly subscription?

    I would appreciate some pointers on understanding how all this works together.

    Thanks in advance.

  8. Anyone able to give a really high level overview of where this fits in with using something like http://parse.com/ ? For example (I’ll take an educated guess) would it be that with the apple specific approach it focused only on turn-based support but is free. WIth http://parse.com/ it’s only free up to a certain level of usage (then paid) but would give you cross platform (e.g. IOS/Android) for players spread across both, plus give you customized server side function, plus support for customized push notifications. Am I close? :)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>