How to use Playtiful package
go to https://game.playtiful.io/#/test/ to test your Game.
paste your game URL (localhost accepted) and test Data, then press Boot button.
1. Add playtiful to your html game.
use script tag
<script src="https://cdn.jsdelivr.net/npm/playtiful/dist/playtiful.min.js" />
or install via NPM
npm install playtiful --save
at this time, playtiful object is an instace of Playtiful class. Access it from window object
let playtiful = window.playtiful;
2. Announce that, your Game is ready.
playtiful.loaded();
3. When your Game is ready, it will receive a JSON that prepresent game data. To get it
playtiful.onData(async (data) => {
//process data JSON here
});
At this time, you should let your Game load the assests. It should be take time.
4. After all assests are loaded, call
playtiful.ready();
At this time, your game is ready to play. But please don't start it now.
5. Your game will be announced to go to main gameplay. To listen it
playtiful.onPlay(async () => {
//go to main gameplay now
})
6. When gameplay is finished. Submit the result by
playtiful.result('game result');
7. Check if Playtiful is ready
// check both playtiful is avaiable and is ready to use
if (playtiful && playtiful.check()) {}