cocos.png

Revision History

DateVersion
2024/08/061.0.1
2024/10/231.0.2

Plugin Download

Go to theResource Downloadpage and download the corresponding plugin project based on your engine version.

Install SDK Plugin

Here, we take Cocos Creator 3.8 as an example:

  1. Import the plugin package by clicking on Extension -> Extension Manager

image.png

  1. Select the project, then click the+sign to import the extension package.

image.png

  1. After the import is successful, open the extension.

image.png

  1. Once the extension is open, a new menu item forMiniGame SDKwill be added to the menu bar. Click on MiniGame SDK -> Control Panel to open the control panel.

image.png

The control panel is shown in the following figure:

image.png

After clicking the Copy button, the SDK directory will be copied to the assets directory. Additionally, the minigame-types file in the declarations folder will be copied to the root directory, as shown in the figure:

image.png

At this point, you can integrate interfaces such as advertising.

  1. Before packaging, check the box for Build MiniGame Package and select the web-mobile platform for packaging. This will automatically build the MiniGame package. If you do not want to build the MiniGame package, simply remove the checkmark (✅) next to Build MiniGame Package .


Integration

When the game finishes loading and enters the main scene, call setGameReadyAsync when the main scene is initialized.

onLoad () {
	minigame.setGameReadyAsync();
}

Before using it, initialize the SDK at the game initialization point (the game entry point) and implement a method to control the sound, which allows the SDK to uniformly manage the game audio during the playback of rewarded and interstitial ads:

MiniGameSDK.init();
MiniGameSDK.pauseSound = () => {
  // todo Handle mute the sound
}

MiniGameSDK.resumeSound = () => {
  // todo Handle unmute the sound
}

After the initialization is completed, you can call the corresponding interfaces.

Below is an introduction to the SDK interfaces:

Rewarded Video Ads
showRewardedVideo(callback: BoolCallback)

  • callback A callback function that is called after the ad playback is completed, with the parameter indicating whether the playback was successful.

MiniGameSDK.showRewardedVideo((isSuccess: boolean) => {
    if (isSuccess) {
        // Handle successful playback logic, grant rewards
    } else {
        // Handle failed playback logic
    }
});

Interstitial Ads
showInterstitial(callback?: BoolCallback)

  • callback A callback function that is called after the ad playback is complete, with the parameter indicating whether the playback was successful.

MiniGameSDK.showInterstitial((isSuccess: boolean) => {
    console.log("show minigame interstitial ad isSuccess: ", isSuccess ? "true" : "false");
})

Interstitial ads do not require the distribution of rewards, so you can choose not to handle the callback function.

Banner Ads
showBanner() : Display banner ads
hideBanner() : Hide banner ads

// Display banner ad
MiniGameSDK.showBanner();

// Hide banner ad
MiniGameSDK.hideBanner();

Language

getLocale()

const lang = MiniGameSDK.getLocale(); // "Assuming the current environment is US English, it returns 'en_US'" 
// Check if the current language is English
if (lang.includes("en")){
	console.info("current language is en");
}
// or
if (lang.substr(0, 2) === "en"){
	console.info("current language is en");
}

Data Storage (Required)

Data Saving

setDataAsync (data: Object): Promise<void>

minigame.player
  .setDataAsync({
    achievements: ['medal1', 'medal2', 'medal3'],
    currentLife: 300,
  })
  .then(function() {
    console.log('data is set');
  });

Get Data

getDataAsync (keys: string[]): Promise<Object>

minigame.player
  .getDataAsync(['achievements', 'currentLife'])
  .then(function(data) {
     console.log('data is loaded');
     var achievements = data['achievements'];
     var currentLife = data['currentLife'];
  });

===========================================

The following interfaces are not required to be integrated under normal conditions, and should only be integrated if our operations team instructs us to do so.

Event Tracking

onGameEvent(eventName: string, label: string)

  • eventName Event Name

  • label Event label

// level: Level event ,level01:First level
MiniGameSDK.onGameEvent("level", "level01");

Payment

Detecting the payment environment
onPaymentReady(readyCallback: Function, consumeCallback: ConsumeCallback)

  • consumeCallback A callback function for order consumption. After a successful payment, the game needs to call this callback to inform that the payment is successful, and the game can then issue rewards.

MiniGameSDK.onPaymentReady((productId: string, isSuccess: boolean) => {
  // todo If the payment is successful but the order consumption fails, a compensation order needs to be issued to distribute the unissued rewards. This callback may be called multiple times because multiple product orders have not been consumed, although the probability of this is relatively low.
});

Note that this interface needs to be called within the callback function of MiniGameSDK.init, as shown in the following code:

MiniGameSDK.init(function() {
  MiniGameSDK.onPaymentReady((productId: string, isSuccess: boolean) => {
    
  });
});

Payment
onPurchase(purchaseConfig: PurchaseConfig, consumeCallback: ConsumeCallback)

  • purchaseConfig Configuration for payment parameters.

  • consumeCallback A callback function for order consumption. After a successful payment, the game needs to call this callback to inform that the payment is successful, and the game can then issue rewards.

    MiniGameSDK.onPurchase(
      { productID: "product1"}, 
      (productId: string, isSuccess: boolean) => {
        if (isSuccess) {
          // Handle successful payment, grant rewards
        } else {
          // Handle failed payment, show failure message
        }
    })

Sharing

onShare(shareConfig: SharePayload, callback: BoolCallback)

  • shareConfig Configuration for sharing parameters.

  • callback A callback function for sharing, with the parameter indicating whether the sharing was successful.

MiniGameSDK.onShare({
  image: base64Picture, // base64-encoded picture
  text: 'your share text'
}, (isSuccess: boolean) => {
  if (isSuccess) {
    // console.info("minigame share success");
  } else {
    // console.error("minigame share failed");
  }
});

Shortcut

createShortcut(shortcutCallback: BoolCallback)

  • shortcutCallback A callback function for sharing, with the parameter indicating whether the sharing was successful.

MiniGameSDK.createShortcut((isSuccess: boolean) => {
  if (isSuccess) {
    // console.info("minigame createShortcut success");
  } else {
    // console.error("minigame createShortcut failed");
  }
});

Simulating Online Environment

Steps:

  1. Open https://minigamecloud.com/testgame

  2. Set isTest to false in minigame.json.

  3. Place the local game link after integrating the SDK into the address bar of the page.

image.png

  1. After clicking "Start Testing," you can simulate the online environment for testing.

Note:If it's a Cocos Creator game, after integrating the SDK, you can directly use the address that runs in the Cocos Creator editor for testing, such as http://localhost:7457

Business Development
Business Development
Official Account
Official Account