Quickstart: Cocos
Add the GOOF helper to a Cocos Creator project, build for Web Mobile, and upload a zip.
1. Add the helper
Copy sdk/cocos/GoofSDK.ts from the GOOF SDK into your project's assets folder. It gives typed access to the GOOF object from TypeScript.
2. Load the SDK script
After a Web Mobile build, add this tag to the built index.html before the game scripts, or add it to your custom build template:
<script src="https://developer.goof.gg/sdk/v1/goof.js"></script>
3. Start the SDK and pause around ads
import { _decorator, Component, game } from 'cc';
const { ccclass } = _decorator;
@ccclass('Boot')
export class Boot extends Component {
async start() {
await GOOF.game.init({ gameId: 'dYOUR_APP_ID' });
GOOF.game.onHide(() => game.pause());
GOOF.game.onShow(() => game.resume());
GOOF.game.gameReady();
}
}
4. A rewarded ad
async onReviveButton() {
const { rewarded } = await GOOF.ads.showRewarded({ adUnitId: 'au_0123456789ab' });
if (rewarded) this.revivePlayer();
else this.showGameOver();
}
5. Build and upload
- Build with the Web Mobile platform.
- Zip the
build/web-mobilefolder. - Upload it in your dashboard and try it in the test player.
Next: Ads and In-app purchases.