6. Extend SDK Game Activity

Extend ClientMainActivity with SDKGameActivity. We need to override two function onCreateSdk(savedInstanceState: Bundle?) and getGameView(parentView: ViewGroup).

  • In onCreateSdk function, we need to call GameSdk.initialize.

  • In getGameView function, return the game screen showing the game.

  • WinZO game SDK uses GameCallbackListener to start and stop the game.

Example:

ClientMainActivity.kt
class ClientMainActivity : SDKGameActivity() {

    override fun onCreateSdk(savedInstanceState: Bundle?) {
        // initialize GameSDK
        GameSdk.initialize(
            context = this,
            clientAccessToken = "<your client access token>",
            isLiveApp = true,
            gameCallbackListener = object :
                GameCallbackListener {
                override fun gameConfig(gameConfig: String) {
                    Log.v("gameTag", "gameConfig received by game")
                }

                override fun startGame() {
                    Log.v("gameTag", "StartGame packet received by game")
                }

                override fun stopGame() {
                    Log.v("gameTag", "StopGame received by game")
                }

            },
            gameName = "your game name",
            gameImageUrl = "game icon url"
        )
    }

    // return view showing gamePlay
    override fun getGameView(parentView: ViewGroup): View {
        val gameView = LayoutInflater.from(this)
            .inflate(R.layout.activity_game_screen, parentView, false)
        return gameView
    }

    override fun onDestroySdk() {
        // do any task on activity destroy
    }
    
    override fun onActivityResultSdk(requestCode: Int, resultCode: Int, data: Intent?) {
        // do any task on activity result
    }
}

You will get clientAccessToken from WinZO.

There are 2 options for handling matchmaking

Option 1: For matchmaking on your side. gameConfig object is:

// gameConfig received in GameCallbackListener
{
    "winzoAccessToken" : "my token",
    "bootAmount" : 10,
    "bootId" : "boot_10"
}

Option 2: For matchmaking on WinZO's side. Opponent data and challenge Id are received in the game config object.

// gameConfig received in GameCallbackListener
{
  "challengeId": "63a00f416b36ff003a71bd78",
  "config": {
    .... //game-related data.
  },
  "playerInfo": {
    "winzoId": "12343342",
    "name": "Rahul",
    "profilePic": "https://d206uh8e4fpi1h.cloudfront.net/Limour.png"
  },
  "opponentsInfo": [
    {
      "winzoId": "12342342",
      "name": "KRISHNENDU2932",
      "profilePic": "https://d206uh8e4fpi1h.cloudfront.net/Hippo.png"
    }
  ]
}

Config is same as set by the game developer.

Last updated