gerb's Forum Posts

  • 3 posts
  • Here's a full example of all the features we offer and require right now. It's a simple example based on your original code, it's verified to work. This should be enough to get you started to implement it.

    Try it by running this URL slumbrous. com/api_example.html in the test tool (cdn.gameplayer.io/testtool/index.html#!/tester). Remove the space in the URL .

    We're releasing a few new features soon, so please don't stick with just the example, and instead look at our online docs at spil.com/html5docs

    <html>
    <head> 
    <script type="text/javascript" src="http://cdn.gameplayer.io/api/js/game.js"></script>
    </head> 
    <style>
    body {
    	background-color:black;
    	color: white;
    }
    </style>
    <body> 
    
    <p>The game is now <span id="gameState">running	</span>!</p>
    
    <p><input value="request an ad" type='button' onclick='requestAd();'></p>
    
    <p><input value="show the logo" type='button' onclick='addLogo();'></p>
    
    <p><input value="show the More Games link" type='button' onclick='addMoreGames();'></p>
    
    <script>
    var gameIsStopped = false; // global value to state if the game should be running
    var apiInstance = null; // global value for the API
    function isPaused() {
         return gameIsStopped;
    };
    function pauseGame() {
        gameIsStopped = true;
        // this next line is for example purposes, you can remove this. use the isPaused() instead.
        document.getElementById("gameState").innerHTML = "paused";
    }
    function resumeGame() {
        gameIsStopped = false;
        // this next line is for example purposes, you can remove this. use the isPaused() instead.
        document.getElementById("gameState").innerHTML = "running";
    }
    // time to load the API
    GameAPI.loadAPI (function (loadedApi) {
         apiInstance = loadedApi; // put the api in the global value
    });
    // request an ad
    function requestAd() {
        if (apiInstance) {
            apiInstance.GameBreak.request(pauseGame, resumeGame);
        } else {
        	console.log("API not loaded!");
        }
    };
    
    function addLogo() {
        if (apiInstance) {
            var logoData = apiInstance.Branding.getLogo();
    	    var logo = document.createElement('img');
    
    	    logo.src = logoData.image;
    	    logo.addEventListener('click', logoData.action);
        
    	    document.body.appendChild(logo);        
        } else {
        	console.log("API not loaded!");
        }
    };
    
    function addMoreGames() {
        if (apiInstance) {
            var linksData = apiInstance.Branding.getLinks();
            if (linksData['more_games']) {
    		    var button = document.createElement('input');
    		    button.value = "Click to see more games!";
    		    button.style.border = "2px solid white";
    		    button.style.fontSize = "20px";
    		    button.style.width = "250px";
    		    button.style.backgroundColor = "#FFCC33";
    		    button.addEventListener('click', linksData['more_games'].action);
    		    document.body.appendChild(button);        
            } else {
    	    	console.log("More-games link not present!");
            }     	
        } else {
        	console.log("API not loaded!");
        }
    };
    
    </script>
    </body>
    [/code:337zocrs]
  • Hi Stelarfox,

    There are some obvious errors, like trying to call the loadAPI function without any kind of scope, as follows:

    loadAPI(fnCallback);[/code:1t5myhn8]
    Your browser doesn't know what to do with that line... I've reworked your code a bit:
    
    [code:1t5myhn8]<script type="text/javascript" src="http://cdn.gameplayer.io/api/js/game.js"></script>
    </head> 
    
    <body> 
    <script>
    var gameIsStopped = false; // global value to state if the game should be running
    var apiInstance = null; // global value for the API
    function isPaused() {
         return gameIsStopped;
    };
    function pauseGame() {
        gameIsStopped = true;
    }
    function resumeGame() {
        gameIsStopped = false;
    }
    // time to load the API
    GameAPI.loadAPI (function (loadedApi) {
         apiInstance = loadedApi; // put the api in the global value
    });
    // request an ad
    function requestAd() {
        if (apiInstance) {
            apiInstance.GameBreak.request(pauseGame, resumeGame);
        }
    };
    </script>[/code:1t5myhn8]
    
    The above example is quite ugly and depends on global values. All in all I would prefer a different way, even though it should work. 
    
    [b]You need to make sure your game responds to the isPaused function[/b], so that the game stops when isPaused() returns 1 (true) and run when it returns 0 (false). Since this was already in the example I presume this is already working in your game.
    
    The test tool is nothing special and you can use any developer console to debug your game normally.
    
    Again: if you get stuck or have questions about the API, find us at the Support channel on spil.com/html5docs  and leave your questions with the Support Crew. They're friendly people.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The current documentation for the API can be found here : spil.com/html5docs. The API is kept compatible with the documentation listed there. There are also tutorials available that you can use as a starting point.

    If you want to test your game, try the on-line test tool: cdn.gameplayer.io/testtool/index.html Just put your game somewhere (any webserver, even localhost, will do) and you're good to go. The tool will provide feedback on your API integration.

    On the test tool page there's also a Support tab, where you can directly create tickets with the Tech Support crew, who aim to help you find answers. Put in a screenshot of whatever problem you're having and we'd be happy to help you be on your way as fast as possible.

    EDIT: Links were removed from my post... added back again

  • 3 posts