Implement Spilgames API

Get help using Construct 2

Post » Thu Mar 20, 2014 9:49 pm

Hi Stelarfox,

There are some obvious errors, like trying to call the loadAPI function without any kind of scope, as follows:
Code: Select all
loadAPI(fnCallback);

Your browser doesn't know what to do with that line... I've reworked your code a bit:

Code: Select all
<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>


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.

You need to make sure your game responds to the isPaused function, 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. :D
B
2
Posts: 3
Reputation: 156

Post » Thu Mar 20, 2014 10:41 pm

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
B
5
S
1
Posts: 23
Reputation: 421

Post » Fri Mar 21, 2014 5:30 am

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

Code: Select all
<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>
B
2
Posts: 3
Reputation: 156

Post » Tue Mar 25, 2014 4:22 pm

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!
B
5
S
1
Posts: 19
Reputation: 1,173

Post » Thu Mar 27, 2014 1:59 am

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.
B
2
Posts: 1
Reputation: 152

Post » Thu Mar 27, 2014 4:40 pm

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.

PixelRebirth wrote: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.
B
6
S
1
G
1
Posts: 39
Reputation: 828

Post » Fri Apr 04, 2014 11:20 am

@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
B
6
S
1
G
1
Posts: 39
Reputation: 828

Post » Fri Apr 04, 2014 7:06 pm

Iris wrote:@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. 8-)
B
23
S
6
G
11
Posts: 1,047
Reputation: 8,065

Post » Sat Apr 05, 2014 1:02 am

PixelRebirth wrote: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. 8-)

That's awesome, thank you!
B
22
S
6
G
3
Posts: 59
Reputation: 4,288

Post » Sat Apr 05, 2014 10:41 am

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?
B
5
S
1
Posts: 13
Reputation: 399

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: draiza and 8 guests