Skip to main content

Quick Start

Quick Start

1. Load the SDK

Add the SDK script to your game's HTML file.

Note: The SDK script must be placed inside the <body> tag. Placing it in <head> may cause the SDK initialization to not work properly.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Game</title>
</head>
<body>
<!-- 1. Load SDK (auto initialization) -->
<script src="https://tudada-game.2bytespublishing.kr/dev/releases/tudadaGameSDK.0.1.5.dev.js"></script>

<!-- 2. Wait for SDK initialization then run game -->
<script>
TudadaGameSDK.waitForReady()
.then(() => {
console.log('SDK initialization complete');

// Dynamically load game script
const gameScript = document.createElement('script');
gameScript.src = './game.js';
document.body.appendChild(gameScript);
})
.catch((error) => {
console.error('SDK initialization failed:', error);
});
</script>
</body>
</html>

2. Use the APIs

Call SDK APIs from your game code:

// game.js - Game code that runs after SDK initialization is complete

// Login
TudadaSDK.login({
success: (res) => {
console.log('Login code:', res.code);
console.log('User ID:', res.userId);
},
fail: (err) => console.error('Login failed:', err.errMsg),
});

// Get system info
const systemInfo = TudadaSDK.getSystemInfoSync();
console.log('Platform:', systemInfo.platform);
console.log('Screen size:', systemInfo.windowWidth, 'x', systemInfo.windowHeight);

// Local storage
TudadaSDK.setStorageSync('score', 1000);
const score = TudadaSDK.getStorageSync('score');

// Audio playback
const audio = TudadaSDK.createInnerAudioContext();
audio.src = './bgm.mp3';
audio.loop = true;
audio.play();

// Rewarded ad (recommended)
TudadaSDK.showRewardedAd({
adUnitId: 'your-ad-unit-id',
success: (res) => { if (res.isEnded) console.log('Reward granted!'); },
});
ad.load().then(() => ad.show());