チュートリアル
プレイヤーの認証
Eメールでログイン(パスワード不要)
- プレイヤーにログイン画面を表示し、メールアドレスの入力を促します
- 以下のサンプルペイロードを使用し、認証リクエストを送信してください - プレイヤーが指定したメールアドレスに確認コードが送られます - 確認コードの有効期限は3分です - この時点では、プレイヤーはまだ認証されていません
// 認証アクションを定義するためには、リクエストタイプとメソッドが常に必要です。
// メールアドレスを認証方法として使用する場合、メールアドレスの入力が必須です。
const payload = {
email: "[email protected]",
requestType: "login",
method: "email",
};
Wortal.authenticateAsync(payload)
.then(result => {
// 成功した場合、ステータスは「保留中」となります。
// これは、確認コードの送信を待っていることを意味します。
console.log("Auth result: " + result.status);
if (result.status === "pending") {
// プレイヤーに確認コードを入力するためのダイアログを表示します。
} else {
// エラーのステータスを処理します。
}
)}
.catch(error => console.log(error));
const payload = {
email: "[email protected]",
code: "1234",
requestType: "login",
method: "email",
};
Wortal.authenticateAsync(payload)
.then(result => {
// 成功した場合、ステータスは「success」となります。
console.log("Auth result: " + result.status);
if (result.status === "success") {
// プレイヤーがログインしました。UIを更新し、プレイヤーデータを取得します。
} else {
// エラーのステータスを処理します。
}
)}
.catch(error => console.log(error));
電話番号でログイン(パスワード不要)
- プレイヤーにログイン画面を表示し、メールアドレスの入力を促します
- 以下のサンプルペイロードを使用し、認証リクエストを送信してください - プレイヤーが指定した電話番号にSMSで確認コードが送られます - 電話番号は必ず「+」と国コードで始まる必要があります - 電話番号には、スペース、ハイフン、および丸括弧を使用することができます - 有効なフォーマットの例: - +1234567890 - +1 (234) 567-890 - +12-345-678-90 - 無効なフォーマットの例: - 1234567890 (国コードの前に「+」が含まれていません) - +123abc456 (文字は使用できません) - 確認コードの有効期限は3分です - この時点では、プレイヤーはまだ認証されていません
// 認証アクションを定義するためには、リクエストタイプとメソッドが常に必要です。
// 電話番号を認証方法として使用する場合、電話番号の入力が必須です。
const payload = {
phone: "+1234567890",
requestType: "login",
method: "phone",
};
Wortal.authenticateAsync(payload)
.then(result => {
// 成功した場合、ステータスは「保留中」となります。
// これは、確認コードの送信を待っていることを意味します。
console.log("Auth result: " + result.status);
if (result.status === "pending") {
// プレイヤーに確認コードを入力するためのダイアログを表示します。
} else {
// エラーのステータスを処理します。
}
)}
.catch(error => console.log(error));
const payload = {
phone: "+1234567890",
code: "1234",
requestType: "login",
method: "phone",
};
Wortal.authenticateAsync(payload)
.then(result => {
// 成功した場合、ステータスは「success」となります。
console.log("Auth result: " + result.status);
if (result.status === "success") {
// プレイヤーがログインしました。UIを更新し、プレイヤーデータを取得します。
} else {
// エラーのステータスを処理します。
}
)}
.catch(error => console.log(error));
リワード広告
リワード広告は、ゲームを収益化するのに適しています。プレイヤーが広告の視聴することで、ゲーム内通貨や追加ライフなどを報酬として受け取ることができます。このチュートリアルでは、リワード広告をゲームに組み込む方法を説明します。
例
プレーヤーが広告を視聴した際に、ゲーム内通貨を報酬として与える3つの方法を紹介します。
- マルチプライヤーを使用し、レベルの終了の際に与えた報酬を増加させる
- リワード広告を使用し、プレイヤーがゲームオーバーの際、再挑戦するチャンスを与える(セカンドチャンス)
- アプリ内ショップでリワード広告を使用し、動画を視聴することで非課金アイテムを与え、さらにアプリ内購入(IAP)のコンバージョンを増加させる
マルチプライヤー
// Player has the finished level and is shown the results screen with the option to watch an ad for bonus currency.
const levelEarnings = 100;
const rewardMultiplier = 3;
function onRewardButtonClicked() {
Wortal.ads.showRewarded("Level 1 Finish",
() => {
// beforeAd
pauseGame();
},
() => {
// afterAd
resumeGame();
},
() => {
// adDismissed
addCurrency(levelEarnings);
},
() => {
// adViewed
addCurrency(levelEarnings * rewardMultiplier);
},
() => {
// noFill
addCurrency(levelEarnings);
});
}
セカンドチャンス
// Player has lost the level and is shown the results screen with the option to watch an ad for a second chance.
function onRewardButtonClicked() {
Wortal.ads.showRewarded("Level 2 Retry",
() => {
// beforeAd
pauseGame();
},
() => {
// afterAd
resumeGame();
},
() => {
// adDismissed
endGame();
},
() => {
// adViewed
continueGame();
},
() => {
// noFill
endGame();
});
}
アプリ内購入(IAP)ショップ
// Player has opened the IAP shop. They can select an item that costs currency or watch an ad for bonus currency.
function onRewardButtonClicked() {
Wortal.ads.showRewarded("IAP Shop",
() => {
// beforeAd
pauseAudio();
},
() => {
// afterAd
resumeAudio();
},
() => {
// adDismissed
// Player doesn't get bonus currency as they didn't finish the ad.
// You can display a UI popup explaining this to the player.
noRewardPopup.show();
},
() => {
// adViewed
addCurrency()
},
() => {
// noFill
// Player doesn't get bonus currency as no ad was available.
// You can display a UI popup explaining this to the player.
noAdAvailablePopup.show();
});
}
"No Fill" の対処方
リワード広告のリクエストが失敗することで、ゲームの進行が停止したりなど、望ましくない事態が発生する可能があります。例えば、リワード広告がゲームに設定されているにもかかわらず、ゲームがフリーズしたり、ボタンなどのUIが反応しないなど、広告が通常通りに表示されない問題が生じた場合、適切な処理を行う必要があります。以下では、これらの問題に対処するための2つの方法を紹介します:
- プレイヤーが報酬を獲得できるように、ソーシャルシェアや招待などの機能を活用する。
- 広告が利用できないことをプレイヤーに通知し、しばらく経ってから再挑戦するよう提案する。
当社のゲームでは、【 1. 】の実装に成功し、プレイヤーのエンゲージメントを向上させるために、この方法を推奨しています。
広告が表示されなかったり、エラーが発生した場合、noFill コールバックを返します。以下は、この問題を処理するためのコールバックです。
ソーシャルシェアの代替案
// Player has the finished level and is shown the results screen with the option to watch an ad for bonus currency.
const levelEarnings = 100;
const rewardMultiplier = 3;
function onRewardButtonClicked() {
Wortal.ads.showRewarded("Level 1 Finish",
() => {
// beforeAd
pauseGame();
},
() => {
// afterAd
resumeGame();
},
() => {
// adDismissed
addCurrency(levelEarnings);
},
() => {
// adViewed
addCurrency(levelEarnings * rewardMultiplier);
},
() => {
// noFill
// No ad was available, so we'll offer the player the option to share the game instead.
shareAlternativePopup.show();
if (shareAlternativePopup.result === "share") {
// Player chose to share the game, so we'll reward them for doing so.
Wortal.context.shareAsync({
intent: "SHARE",
payload: {
text: "I just finished level 1!",
image: "https://example.com/level1.png",
data: {
level: 1,
// Friends that open the game via the share link will receive a bonus.
// This can be accessed via Wortal.session.getEntryPointData().
shareBonus: 100
}
}
}).then(() => {
// Share was successful, so we'll reward the player.
addCurrency(levelEarnings * rewardMultiplier);
}).catch((error) => {
// Share failed, so we'll just reward the player for finishing the level.
addCurrency(levelEarnings);
});
} else {
// Player chose not to share the game, so we'll just reward them for finishing the level.
addCurrency(levelEarnings);
}
});
}