Construct Arcade SDK (CASDK)
Easily add Construct Arcade leaderboards to your game.
If you have any questions about this page, get help on the Discord server.
Leaderboards
Leaderboards are a great way to encourage players to replay and improve their scores. We make it very easy to embed your own leaderboards.
Leaderboards ID
Make sure you requested a leaderboards id on the Discord server.
A-Frame Component
To add leaderboards to an A-Frame game, make sure you have a leaderboard id.
Download
leaderboard component (right-click > “Save As…”).
You can add a leaderboard easily to your scene with the following snippet:
<!-- in the head --> <script src="<path-to-the-leaderboard-component.js>"></script> <!-- in the a-scene --> <a-entity ca-leaderboard="leaderboardId: <your-id>; title: 'Leaderboard'; debug: true"> </a-entity>
Before releasing your game, remove the debug: true
flag, which fills the
leaderboard with dummy data for local development.
Origin-Lock
Construct Arcade Leaderboard servers may only be accessed from the constructarcade.com domain.
In-App Purchases/Unlockables
Add purchasable and unlockable items to your games!
The CASDK allows you to manage a user inventory via the account system, which means once a user unlocks an item in game, they will have access to it whenever they return to your game. This unlock can be triggered by any in-game activity, or by spending Construct Coins. Latter will be an option for you to earn some money with the games you have created!
Unlockables vs in-app purchases
To allow users to unlock items via in-game activity (e.g. reaching a certain score), create an item with a price of “0” and trigger a purchase of this item when the user has achieved the required task.
To allow you to include in-app purchases (IAPs) in your application, Construct Arcade provides four methods via our SDK (CASDK).
Game ID and Item ID
For security reasons the server-side database is completely manged by us. Item creation and price changes have to be done through us.
casdk.purchaseItem(gameId, itemId, price)
returns a promise containing response.success or response.error
gameId
is the ID of the game, which is provided by usitemId
is the internal name of the itemprice
is the price which has to be stored on the server as well
Example:
AFRAME.registerComponent('ca-purchase', { schema: { itemId: { type: 'string', default: ''}, gameId: { type: 'string', default: ''} }, init: function() { this.el.addEventListener('click', this.onClick.bind(this)); this.clicked = false; this.bought = false; this.buying = false; document.querySelector('a-scene').addEventListener("gameover", this.onReset.bind(this)); }, onReset: function() { this.el.setAttribute('text', { value: ''}) this.clicked = false; this.bought = false; }, onClick: function(e) { if(state == STATE_GAME) return; if(!this.clicked) { this.el.setAttribute('text', { value: 'Click again to confirm purchase.'}) this.clicked = true; return; } if(this.bought || this.buying) return; this.buying = true; if (!('casdk' in window)) { this.el.setAttribute('text', { value: 'Error: casdk missing'}); console.error('ca-purchase-component: CASDK missing.'); return; } if(!this.price) { this.buying = false; this.el.setAttribute('text', { value: 'A network error has occured'}) } this.el.setAttribute('text', { value: 'Confirming purchase...'}) casdk.purchaseItem(this.data.gameId, this.data.itemId, this.price).then( (response) => { this.buying = false; if(response) { console.log(response); if(response.success) { this.el.sceneEl.components.game.checkUnlockedItems(true); this.el.setAttribute('text', { value: 'unlocked'}); this.el.setAttribute('class', ''); this.bought = true; } else { this.el.setAttribute('text', { value: 'Not enough funds.'}); } } else { this.el.setAttribute('text', { value: ''}); this.el.sceneEl.exitVR(); casdk.loginButtonPressed(); } } ); }, });
casdk.getInventory()
returns a promise containing the response:
false
if the user is not logged in- otherwise contains the inventory of the user as an array of objects:
{inventory: [{itemId: <string>}, ...]}
casdk.getAmountCurrency()
returns a promise containing the amount of coins a user owns in the response:
{currency: <number>}
, or false
if the user is not logged in.
This function is called on pageload and dispatches a casdk-currency-updated
event on window
.
casdk.getCatalog(gameId)
returns a promise containing the catalog of game items
This catalog needs to be set up by us.
This function does not require the user to be logged in.
The catalog is returned as an array of game items:
{catalog:[{ itemId: <string>, displayName: <string>, description: <string>, price: <number> },...]}