Cross-platform utilities for Cocos2d-x
C++ Objective-C++ Objective-C
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Android
Apple
Examples
ABDatabase.hpp
AdKit.cpp
AdKit.hpp
Analytics.cpp
Analytics.hpp
CompilerEnhancements.hpp
CryptoKit.cpp
CryptoKit.hpp
Date.cpp
Date.hpp
Device.cpp
Device.hpp
Doxyfile
Facebook.hpp
Features.hpp
FiniteTimeActions.cpp
FiniteTimeActions.hpp
GameKit.cpp
GameKit.hpp
IAPKit.cpp
IAPKit.hpp
InfiniteParallaxNode.cpp
InfiniteParallaxNode.hpp
KVDatabase.cpp
KVDatabase.hpp
LICENSE
Log.cpp
Log.hpp
Math.hpp
MawKit.h
Random.hpp
Range.hpp
Readme.md
_AdKit.hpp
_Analytics.hpp
_GameKit.hpp
_IAPKit.hpp
_Log.hpp

Readme.md

MawKit

MawKit is a library built on top of Cocos2d-x offering useful cross-platform utilities to implement platform-specific features like leaderboards, achievements, or in-app purchases quickly.

Main features

  • Leaderboards and achievements: Game Center (iOS, OS X) / Google Play Games (Android).
  • In-app purchases: App Store (iOS, OS X), Google Play (Android).
  • Ads: AdMob and AdColony (iOS, Android, not supported on OS X).
  • Analytics: Fabric (iOS, Android, OS X) and MixPanel (iOS).
  • Mathematical utilities: ranges, random number generator.

Installation

Requirements

  • CocoaPods (iOS).

 Android

To do...

iOS / OS X

  1. Run pod init in proj.ios_mac folder to create a Podfile. [Gif]

  2. Add the following dependencies for iOS:

    • pod 'SecureNSUserDefaults'
    • pod 'Fabric' # Fabric
    • pod 'Crashlytics' # Fabric
    • pod 'FBSDKCoreKit' # Facebook
    • pod 'FBSDKShareKit' # Facebook
    • pod 'FBSDKShareKit' # Facebook
    • pod 'Bolts' # Facebook
    • pod 'Google-Mobile-Ads-SDK' # AdMob
    • pod 'Mixpanel' # MixPanel
  3. Add the following dependencies for OS X:
    • pod 'SecureNSUserDefaults'
    • pod 'Fabric' # Fabric
    • pod 'Crashlytics' # Fabric
  4. Open Xcode project and locate Build Settings tab of iOS target: [Gif]
    1. Look for GCC_PREPROCESSOR_DEFINITIONS and prepend $(inherited) for release and debug build.
    2. Look for LIBRARY_SEARCH_PATHS, prepend $(inherited) and append $(PROJECT_DIR)/../Classes/MawKit/Apple/iOS for release and debug build.
    3. Look for OTHER_LDFLAGS and prepend $(inherited) for release and debug build.
  5. Open Xcode project and locate Build Settings tab of OS X target:
    1. Look for GCC_PREPROCESSOR_DEFINITIONS and prepend $(inherited) for release and debug build.
    2. Look for LIBRARY_SEARCH_PATHS and prepend $(inherited) for release and debug build.
    3. Look for OTHER_LDFLAGS and prepend $(inherited) for release and debug build.
  6. Run pod install to install pods.
  7. Add Game Center and In-App Purchase capabilities on both iOS and OS X. [Gif]
  8. Import MawKit folder in Xcode.
  9. Remove MawKit/Android and MawKit/Example folders from Xcode project. [Gif]
  10. Check files .mm and .a files in MawKit/Apple/iOS so they are only build on iOS target.
  11. Check files .mm files in MawKit/Apple/OS X so they are only build on OS X target.
  12. Add Examples/ios_ids.plist and Examples/mac_ids.plist to Resources folder. Don't forget to add it in Xcode so it gets bundled. [Gif]
  13. Add Examples/MKConstants.h and Examples/MKUtils.cpp to project. MKUtils.cpp should be added to iOS and OS X targets. [Gif]
  14. Set up and fix Fabric for iOS and OS X. This is required as Fabric.framework is different for iOS and OS X and Fabric's app does not support multiplatform targets by default. Fix is as easy as getting both versions and storing them at different paths. This can be done with the two following steps:
    1. Follow Fabric instructions to set up Fabric for iOS target. When finished you'll have a Fabric.framework folder inside proj.ios_mac. You'll have to move it to proj.ios_mac/iOS subfolder and update Xcode project to reflect the change.
    2. Follow Fabric instructions again to set up Fabric for OS X target. When finished you'll have a Fabric.framework folder inside proj.ios_mac. You'll have to move it to proj.ios_mac/osx subfolder and update Xcode project to reflect the change.
  15. Set up MixPanel for iOS (MixPanel is not supported on OS X):
    1. Open proj.ios_mac/ios/AppDelegate.mm and add in the header #import "Mixpanel.h" to import MixPanel.
    2. Open proj.ios_mac/ios/AppDelegate.mm and add in the header #define MIXPANEL_TOKEN @"YOUR_MIXPANEL_TOKEN_HERE" to set up MixPanel's token.
    3. Open proj.ios_mac/ios/AppDelegate.mm and add this line to - (BOOL)application:didFinishLaunchingWithOptions: method: [Mixpanel sharedInstanceWithToken:MIXPANEL_TOKEN]; to init MixPanel analytics on startup.
  16. To support Game Center on iOS, convert _window ivar into a property in proj.ios_mac/ios/AppDelegate.h: @property ( nonatomic, strong ) UIWindow *window; (nothing is required on OS X).

Usage

Everything defined and implemented by MawKit can be found on MK namespace.

 GameKit

To do...

in-App purchases

To do...

KVDatabase

To do...

Mathematical utilities

Random

first-use

[Random loop Gif]

Ranges

auto range = MK::Range<int>(10, 20);
MK::Log::debug(
    "Random number in [%d, %d] range: %d",
    range.first(),
    range.last(), 
    range.randomInteger()
);