빠른 시작
빠른 시작
1. SDK 로드
게임 HTML 파일에 SDK 스크립트를 추가합니다.
주의: SDK 스크립트는 반드시
<body>태그 안에 배치해야 합니다.<head>에 넣으면 SDK 초기화가 정상적으로 동작하지 않을 수 있습니다.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Game</title>
</head>
<body>
<!-- 1. SDK 로드 (자동 초기화) -->
<script src="https://tudada-game.2bytespublishing.kr/dev/releases/tudadaGameSDK.0.1.5.dev.js"></script>
<!-- 2. SDK 초기화 대기 후 게임 실행 -->
<script>
TudadaGameSDK.waitForReady()
.then(() => {
console.log('SDK 초기화 완료');
// 게임 스크립트 동적 로드
const gameScript = document.createElement('script');
gameScript.src = './game.js';
document.body.appendChild(gameScript);
})
.catch((error) => {
console.error('SDK 초기화 실패:', error);
});
</script>
</body>
</html>
2. API 사용
게임 코드에서 SDK API를 호출합니다:
// game.js - SDK 초기화 완료 후 실행되는 게임 코드
// 로그인
TudadaSDK.login({
success: (res) => {
console.log('로그인 코드:', res.code);
console.log('유저 ID:', res.userId);
},
fail: (err) => console.error('로그인 실패:', err.errMsg),
});
// 시스템 정보 조회
const systemInfo = TudadaSDK.getSystemInfoSync();
console.log('플랫폼:', systemInfo.platform);
console.log('화면 크기:', systemInfo.windowWidth, 'x', systemInfo.windowHeight);
// 로컬 스토리지
TudadaSDK.setStorageSync('score', 1000);
const score = TudadaSDK.getStorageSync('score');
// 오디오 재생
const audio = TudadaSDK.createInnerAudioContext();
audio.src = './bgm.mp3';
audio.loop = true;
audio.play();
// 보상형 광고 (권장)
TudadaSDK.showRewardedAd({
adUnitId: 'your-ad-unit-id',
success: (res) => { if (res.isEnded) console.log('보상 지급!'); },
});
ad.load().then(() => ad.show());