Implement Spilgames API

0 favourites
  • Hello, is there a last plugin that works. I am asking because it says it cannot be done using the "browser" command but should be used ussing their api... can someone help me in "how" can i do that?

  • hello i am starting with a new one just to make the spilgames api work and not have to wait a lot for my game to load that is longer so started a blank one with just one button

    i added just before the /head... (deleting the original </head> and <body>...

    (code inside index.html)

    [quote:117xy1vy]

    <script type="text/javascript" src="http://cdn.gameplayer.io/api/js/game.js"></script>

    </head>

    <body>

    <script>

    GameAPI.loadAPI (function (apiInstance) {

    });

    loadAPI(fnCallback);

    apiInstance.stop=0;

    function isPaused() {

    return apiInstance.stop;

    };

    function requestAdd() {

    apiInstance.GameBreak.request(pauseGame, resumeGame);

    };

    function pauseGame() {

    apiInstance.stop=1;

    }

    function resumeGame() {

    apiInstance.stop=0;

    }

    </script>

    and now the tester says the api is loaded but...nothing is is working at all not even the button

    [attachment=0:117xy1vy][/attachment:117xy1vy]

    that is the code in the construct... so my idea as you see is just to.

    step one load the api...that the tool say it did..

    step 2 i press the button so when that happen the function requestAdd is executed supposedly, that will trigger the other 2 functions changing the value to the apiInstance.stop that i read in every cicle but.. for some reason is not working because is not showing me any text...

    can someone help?

  • 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

  • thanks but I already read all on there.. and then i tried to fix it making this code... and for some reason my program just stop working but it does not give me any kind of feedback at all.

    does the test tool stops error messages?, because if i do not test on your site...the api is not available so it gives error because does not load and.. if i test at your site, i have no feedback so.. you can see the problem.

  • 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.
  • ok i am making some other mistake because its not working from anywere except from my own computer. and when done the api is not running...

    is there any way to run the api from my local host (or to reach it) so i can test with debug messages?

    and by the way As soon as i set the addRequest on my program it still stops working as before the changes

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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]
  • OK, I've got as far as I can and now I need help!

    I'm not a coder so copying and pasting stuff has got me this far!

    The game shows and ad while it's loading. API loaded, Splash Screen, Logo and In-Game ads are green and ticked in the test tool.

    I can't get a splash logo anim to play. I'm sure the easiest way would be to have the ad play, then when it is finished, wait until the game is loaded and run the splash anim before letting the game start. This could all be done in the index.html

    I tried to do this but I failed!

    Then, I want the logo's in the game to change depending on which logo is loaded. I'm assuming I can do this by loading an image to replace the current logo from wherever they have been loaded?

    Then I want my "more games" button to link to wherever the API wants it to. This I thought would be simple but I can't work it out!

    Thanks to anyone who's even read to the end of this post!

  • I'm bumping this up because I need this as well.

    Thanks to gerb's code I managed to make a -very- crude plugin and a example that passes all Spilgames tests.

    You can check it out here if you wish bit.ly/1dP6TJ5

    The plugin is very far from perfect, as is mainly copy&paste from the API site. The main problem is that the logos and the buttons are drawn outside the game frame and I can't figure out how to draw them inside and controlling their positions and so on.

    Hopefully someone that knows more about C2 plugins can help out.

  • I passed QA after discussing the problems with QA team. As far as I know, Spilgames is updating their API at the moment. So if we use the old plugin to implement the API, it may cause some frustrating issues.

    I doubt you will get into real trouble even past the deadline as long as you're actively trying to resolve the issues raised by QA.

    I need to tell you guys that I currently do not recommend using my plugin. Alone this week there have been at least three updates to the API. Some things in the plugin are deprecated and newer methods aren't in there yet.

    I tried to keep up and used an adjusted version to submit my game again today along with a message for the QA department. However my contact at Spilgames appears to be on vacation, so I hope the forwarding and all goes well and I get a response soon.

  • PixelRebirth let me ask you one more thing, how I get the branding link via the plugin? I tried to use BrandingLink expression but it just open a new empty window - response from QA :s

  • PixelRebirth let me ask you one more thing, how I get the branding link via the plugin? I tried to use BrandingLink expression but it just open a new empty window - response from QA :s

    Unfortunately you are using a version of the plugin which is obsolete.

    But let me tell you that I'm currently in contact with the nice folks at spilgames to collaborate on an updated version of my plugin. There should be results next week and then the plugin will basically be officially approved and overhauled by Spilgames. A fully working solution for every C2 user.

  • But let me tell you that I'm currently in contact with the nice folks at spilgames to collaborate on an updated version of my plugin. There should be results next week and then the plugin will basically be officially approved and overhauled by Spilgames. A fully working solution for every C2 user.

    That's awesome, thank you!

  • I have been following this post for sometime now and I just had a quick question. At the time of QA submission, is it standard for developers to send the source file for the game to Spilgames? Is it secure? Are any of you submitting via URL?

  • I have been following this post for sometime now and I just had a quick question. At the time of QA submission, is it standard for developers to send the source file for the game to Spilgames? Is it secure? Are any of you submitting via URL?

    You do not send the capx file or project folder, but the exported and minified game. Have you been asked to include the source file?

    I usually use a zip archive including the game files to submit.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)