복사해서 붙여넣는 예제: index.html 하나
이 페이지는 아무것도 바꾸지 않고 붙여넣고, 실행하고, zip으로 묶어 업로드할 수 있는 파일 하나입니다. 첫 제출에 필요한 SDK의 모든 부분인 init, 로딩 신호, gameplayStart와 gameplayStop, 대체 처리가 있는 보상형 광고 하나, 저장을 사용하는 가장 작은 게임입니다. 약 10분이 걸립니다. 미드게임 광고와 happytime까지 다루는 더 긴 두 파일짜리 튜토리얼은 15분 만에 만드는 최소 게임이고, 콘솔까지 포함한 번호 순서 안내는 30분 만에 첫 게임 출시하기입니다.
1. index.html로 저장하기#
coin-tap이라는 빈 폴더를 만들고 그 안에 파일을 index.html로 저장하세요. 다른 것은 필요 없습니다.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Coin Tap</title>
<!-- The real SDK script. It must come before your own code. -->
<script src="https://sdk.zokogames.com/zokogames-sdk-v1.js"></script>
<style>
html, body { margin: 0; height: 100%; background: #14161f; color: #fff; font: 18px sans-serif; text-align: center; }
main { padding-top: 12vh; }
button { font: inherit; padding: 12px 24px; margin: 6px; }
#coin { width: 120px; height: 120px; border-radius: 50%; border: 0; background: #ffc531; touch-action: manipulation; }
[hidden] { display: none !important; }
</style>
</head>
<body>
<main>
<h1>Coin Tap</h1>
<p>Score <b id="score">0</b> | Time <b id="time">10</b> | Best <b id="best">0</b></p>
<p><button id="coin" aria-label="Coin" hidden></button></p>
<p id="msg">Loading...</p>
<button id="play" disabled>Play</button>
<button id="bonus" hidden>Watch an ad for +5 seconds</button>
</main>
<script>
var SDK = window.ZokoGames && window.ZokoGames.SDK; // undefined if the script was blocked
var $ = function (id) { return document.getElementById(id); };
var usable = false, running = false, score = 0, best = 0, left = 10, extra = 0, timer = 0;
// Every SDK call goes through here: if the SDK is missing, disabled or a call fails, the game still runs.
// SDK errors are plain { code, message } objects, not Error instances.
function zoko(call) {
if (!usable) return Promise.resolve(undefined);
return Promise.resolve().then(call).catch(function (e) {
console.warn("SDK:", e && e.code, e && e.message);
});
}
function boot() {
var ready = SDK ? SDK.init() : Promise.resolve(); // init() never rejects
return ready
.then(function () { usable = !!SDK && SDK.environment !== "disabled"; })
.then(function () { return zoko(function () { return SDK.game.loadingStart(); }); })
.then(function () {
if (usable) { // saves are synchronous and throw on error, so keep them inside try
try { best = Number(SDK.data.getItem("best")) || 0; } catch (e) { console.warn("SDK:", e.code); }
}
$("best").textContent = best;
$("bonus").hidden = !usable;
return zoko(function () { return SDK.game.loadingStop(); }); // the first screen is ready
})
.then(function () { $("msg").textContent = "Tap the coin as often as you can."; $("play").disabled = false; });
}
function setRunning(on) {
if (on === running) return;
running = on;
clearInterval(timer);
if (on) timer = setInterval(tick, 1000);
zoko(function () { return on ? SDK.game.gameplayStart() : SDK.game.gameplayStop(); });
}
function startRound() {
score = 0; left = 10 + extra; extra = 0;
$("play").hidden = $("bonus").hidden = true;
$("coin").hidden = false;
$("msg").textContent = "";
render();
setRunning(true); // input is live now: gameplayStart
}
function tick() { left -= 1; render(); if (left <= 0) endRound(); }
function endRound() {
setRunning(false); // round over: gameplayStop
$("coin").hidden = true;
$("play").hidden = false;
$("bonus").hidden = !usable;
$("msg").textContent = "Round over: " + score;
if (score > best) {
best = score;
$("best").textContent = best;
if (usable) {
try { SDK.data.setItem("best", String(best)); } catch (e) { console.warn("SDK:", e.code); }
}
}
}
// Rewarded ad with a fallback: the reward is granted only when the ad finished; every other outcome just carries on.
$("bonus").addEventListener("click", function () {
var finished = false;
$("bonus").disabled = $("play").disabled = true;
zoko(function () {
return SDK.ad.requestAd("rewarded", {
adFinished: function () { finished = true; },
adError: function (e) { console.info("No ad:", e.code); } // adsDisabled before full launch, unfilled, adblock...
});
}).then(function () {
$("bonus").disabled = $("play").disabled = false;
if (finished) { extra = 5; $("msg").textContent = "+5 seconds next round."; }
else { $("msg").textContent = "No ad right now. Play on."; } // the fallback
});
});
$("coin").addEventListener("pointerdown", function (e) { e.preventDefault(); if (running) { score += 1; render(); } });
$("play").addEventListener("click", startRound);
window.addEventListener("blur", function () { if (running) setRunning(false); }); // pause when focus leaves
window.addEventListener("focus", function () { if (!$("coin").hidden) setRunning(true); });
function render() { $("score").textContent = score; $("time").textContent = left; }
boot();
</script>
</body>
</html>SDK가 차단되었거나 SDK.environment가 "disabled"여도 게임은 계속 동작합니다. zoko()가 모든 호출을 건너뛰고 포털이 필요한 버튼은 숨겨진 채로 남습니다. SDK 스크립트 URL은 실제 주소인 https://sdk.zokogames.com/zokogames-sdk-v1.js입니다. 이 파일을 빌드에 복사하지 마세요.
2. 각 부분이 하는 일#
| 부분 | SDK 호출 | 있는 이유 |
|---|---|---|
<head>의 스크립트 태그 |
없음 | window.ZokoGames.SDK를 정의합니다. 이것이 없으면 업로드 보고서가 no_sdk 경고를 냅니다. |
boot() |
SDK.init(), 이어서 SDK.environment |
init()은 반드시 먼저 호출해야 하며 절대 거부되지 않습니다. 실패하면 "disabled"로 나타납니다. |
| 로딩 | SDK.game.loadingStart(), SDK.game.loadingStop() |
로딩 시간과 플레이 시간을 구분합니다. 첫 화면을 플레이할 수 있게 되면 loadingStop을 호출하세요. |
| Play와 라운드의 끝 | SDK.game.gameplayStart(), SDK.game.gameplayStop() |
gameplayStart는 미리보기 체크리스트가 가장 먼저 기다리는 호출입니다(로드 후 20초 이내). gameplayStop은 라운드를 마무리하며 창이 포커스를 잃을 때도 실행됩니다. |
| 보너스 버튼 | SDK.ad.requestAd("rewarded", { adFinished, adError }) |
보상은 adFinished에서만 줍니다. 기본 출시에서는 포털이 adsDisabled로 응답하므로 가장 먼저 보게 되는 것은 대체 분기입니다. |
| 최고 점수 | SDK.data.getItem, SDK.data.setItem |
동기식이며 문자열만 받습니다. 오류가 나면 { code, message }를 던지므로 try 안에 둡니다. |
3. 내 컴퓨터에서 실행하기#
localhost에서는 SDK가 모든 호출에 스스로 응답하므로 포털도 계정도 필요 없습니다. 폴더를 HTTP로 제공한 다음(file://은 로컬로 인정되지 않습니다) 주소 끝에 ?sdk_debug=true를 붙여 여세요.
cd coin-tap
npx http-server . -p 8080
# or, without Node.js:
python3 -m http.server 8080
# open http://localhost:8080/?sdk_debug=true페이지가 열리면 [ZokoGames SDK] Local mode: ... 줄이 하나 보이고, Play가 활성화되기 전에 [ZokoGames SDK] call game.loadingStart와 call game.loadingStop이 나옵니다. Play를 누르면 call game.gameplayStart가, 10초 뒤에는 call game.gameplayStop이 나옵니다. Watch an ad for +5 seconds를 누르면 Local ad (rewarded)라고 적힌 자리표시자가 3초 동안 페이지를 덮고, 그다음 메시지가 "+5 seconds next round."로 바뀝니다. 콘솔에 ZokoGames.SDK.environment를 입력하면 "local"이 출력됩니다. 주소에 &ad_response=unfilled를 붙이면 대체 처리("No ad right now. Play on.")를 볼 수 있고, &ad_response=adsDisabled를 붙이면 기본 출시에서 어떻게 보이는지 확인할 수 있습니다. 모든 스위치는 테스트에 있습니다.
그런 다음 미리보기 도구를 열고 http://localhost:8080/을 입력해 게임 불러오기를 누르세요. 한 라운드를 플레이하고 보너스 버튼을 누르면 체크리스트에서 SDK 초기화(init 호출), loadingStop 호출, gameplayStart 호출, gameplayStop 호출, 보상형 광고 요청, Data 모듈 사용이 체크되고, 타이밍 줄에 첫 gameplayStart까지의 시간이 20초 미만으로 표시됩니다. 미드게임 광고와 happytime 항목은 회색으로 남지만 첫 제출에는 문제가 되지 않습니다.
4. zip으로 묶기#
index.html은 아카이브의 루트에 있어야 합니다. 최상위 폴더 하나 안에 있어도 허용되며, __MACOSX와 .DS_Store 같은 시스템 파일은 무시됩니다.
| 시스템 | 명령 또는 동작 | 결과 |
|---|---|---|
| macOS 또는 Linux | cd coin-tap && zip ../coin-tap.zip index.html |
폴더 옆에 coin-tap.zip 생성 |
| Windows 10 또는 11 | 폴더에서 tar -a -c -f ..\coin-tap.zip index.html 실행 |
폴더 옆에 coin-tap.zip 생성 |
| 파일 관리자를 쓰는 모든 시스템 | 폴더가 아니라 폴더 안의 파일을 선택한 다음 압축 | 루트에 index.html이 있는 zip |
unzip -l coin-tap.zip(macOS, Linux) 또는 tar -tf coin-tap.zip(Windows)으로 확인하세요. 목록에 index.html이 앞에 아무것도 붙지 않은 채 나와야 합니다. 이전 버전의 Windows PowerShell에서는 Compress-Archive가 zip 항목 이름에 백슬래시를 넣을 수 있고 검사기는 이를 unsafe_path로 반려하므로, tar나 파일 관리자를 사용하세요.
5. 업로드하기#
30분 만에 첫 게임 출시하기의 6단계와 7단계를 따르세요. 빌드 단계의 게임 zip 파일을 여기에 끌어다 놓으세요에 coin-tap.zip을 놓습니다. SDK가 감지되고 오류가 없다는 "빌드 v1이(가) 검증을 통과해 게시되었습니다."가 보여야 합니다. 심사 제출을 누르려면 그 전에 직접 쓴 설명, 조작법, 태그, 커버가 여전히 필요합니다.
다음 단계#
- 15분 만에 만드는 최소 게임: 같은 개념을 미드게임 광고,
happytime, 포털의 음소거 설정과 함께 다룹니다. - 소개, init, 오류:
init, 환경, 모든 오류 코드를 설명합니다. - 문제 해결: 콘솔에 아무 반응이 없거나 업로드가 반려될 때 참고하세요.