How to implement GKTurnBasedMatchOutcomeCustomRang

2019-08-17 00:51发布

问题:

I've looked in the Apple GameKit Programming Guide, as well as the documentation of the GKTurnBasedParticipant to try and figure out how to implement the custom range. Apple docs say:

"Optionally, it may also use an OR operation to include a custom match outcome for your specific game. Game Center does not use the custom value; it exists to allow your game to provide additional information at the end of the match. The custom value must fit in the range provided by the GKTurnBasedMatchOutcomeCustomRange constant." ....

 GKTurnBasedMatchOutcomeFourth = 9,
    GKTurnBasedMatchOutcomeCustomRange = 0x00FF0000
};
typedef NSInteger GKTurnBasedMatchOutcome;*

I am not sure what to do to make a custom value or string for the outcome of the match. Any help would be appreciated!

Thanks, Tams

回答1:

To create a custom match outcome enum, adapt the following to your purposes:

typedef enum
{
    GKTurnBasedMatchOutcomeCustom0 = 0 | GKTurnBasedMatchOutcomeCustomRange,
    GKTurnBasedMatchOutcomeCustom1 = 1 | GKTurnBasedMatchOutcomeCustomRange,
    GKTurnBasedMatchOutcomeCustom2 = 2 | GKTurnBasedMatchOutcomeCustomRange,
    ...
    GKTurnBasedMatchOutcomeCustomLast = 65536 | GKTurnBasedMatchOutcomeCustomRange
} GKTurnBasedMatchOutcome_Custom;

For example, GKTurnBasedMatchOutcomeCustom1 will be equal to 0xFF0000.

Essentially, you are allowed a maximum of 0xFFFF+1 (65536 in decimal) custom match outcome states.



回答2:

I think you need to start from 1 rather than 0. Thus:

GKTurnBasedMatchOutcomeCustom0 = 1 | GKTurnBasedMatchOutcomeCustomRange

etc

Otherwise, the match is not considered to be over if you use GKTurnBasedMatchOutcomeCustom0.

You may want to check it out for yourself.



标签: ios gamekit