Your API requests are authenticated using the API key and Private Key. Any request that doesn't include this will return an error.
Follow the steps below to create a game and generate an API and private keys.
The Private Key is only visible at the time you generate the keys and after that you will never be able to see it again, so make sure you copy it.
Setting up Ad surfaces
To implement advertisements in your game, you must first define ad surfaces within the ReneVerse Portal. Follow the steps below to create ad surfaces in your games.
Install the SDK
The best way to interact with our API is to use one of our official libraries:
# Install via NPM
npm install --save @reneverse/rene-sdk-phaser
Let's initialize the Phaser hooks provided in rene-sdk-phaser with the previously acquired credentials, retrieve all ad surfaces configured in the ReneVerse portal, and serve Ads in a Phaser 3 game.
import { PhaserHooks } from"@reneverse/rene-sdk-phaser";import { IRefPhaserGame, PhaserGame } from"./game/PhaserGame";import { useRef } from"react";functionApp() {// References to the PhaserGame component (game and scene are exposed)constphaserRef=useRef<IRefPhaserGame|null>(null);// Initialize PhaserHooks with API Key and Private Key for ReneVerseconstphaserHooks=newPhaserHooks({ apiKey:'<YOUR API KEY>', privateKey:'<YOUR PRIVATE KEY>', });constserveAd=async () => {if (phaserRef.current) {constscene=phaserRef.current.scene;if (scene) {// Fetch Ad surfaces configured in the ReneVerse portalconstadSurfaces=awaitphaserHooks.useReneVerse().getAdSurfaces();// Check if there are any ad surfaces configured in the ReneVerse portalif (!adSurfaces.items.length) {console.log("No ad surfaces found");return; }// Fetch Ad from ReneVerseconstad=await phaserHooks.useReneVerse().getAd(adSurfaces.items[0].adSurfaceId);// Load Ad imageif (ad.adId) {scene.load.image("dynamicAd",ad.url asstring);scene.load.once("complete", () => {// Get Random Positionconstx=Phaser.Math.Between(100,900);consty=Phaser.Math.Between(100,600);// `add.sprite` is a Phaser GameObjectFactory method and it returns a Sprite Game Object instanceconstadSurface=scene.add.sprite(x, y,"dynamicAd");// Set display sizeadSurface.setDisplaySize(300,200); };scene.load.start(); } } } }// Creating a button to call the serveAd functionreturn ( <div><PhaserGame ref={phaserRef} /><button onClick={serveAd}> Serve Ad</button></div> );}export default App;