Jump to content

How to set up the Spil API with the Phaser basic template?


Biggerplay
 Share

Recommended Posts

Anyone know how to do that? I've got this...

 

GameAPI.loadAPI(function(API) {    // The API is ready for use.    // It can be accessed by using the "API" variable.    // For example, the following call requests a branding logo:    GameAPI.GameBreak.request(fnPause, fnResume);});var apiTry= 2;function fnPause(){    var apiTry = 0;}function fnResume(){    var apiTry = 1;    // Create your Phaser game and inject it into the gameContainer div.    // We did it in a window.onload event, but you can do it anywhere (requireJS load, anonymous function, jQuery dom ready, - whatever floats your boat)    var game = new Phaser.Game(700, 600, Phaser.AUTO, 'gameContainer');    API.Branding.getLogo();    // Add the States your game has.    // You don't have to do this in the html, it could be done in your Boot state too, but for simplicity I'll keep it here.    game.state.add('Boot', BasicGame.Boot);    // Now start the Boot state.    game.state.start('Boot');}

The ad test shows, but then nothing, just a black screen.

Link to comment
Share on other sites

Hi, I put it in my index.html page, but I suppose you could put it anywhere as long as you do something like this:

       window.onload = function () {            GameAPI.loadAPI(function (API) {                var myGame = new Phaser.Game(1024, 672, Phaser.AUTO, 'game');                myGame.state.add('boot', Screen.Boot, true);                myGame.state.add('preloader', Screen.Preloader);                myGame.state.add('gamescreen', Screen.GameScreen);            });        }

Then you can call GameAPI.GameBreak whenever you want to show an ad.

Link to comment
Share on other sites

Hi, I put it in my index.html page, but I suppose you could put it anywhere as long as you do something like this:

       window.onload = function () {            GameAPI.loadAPI(function (API) {                var myGame = new Phaser.Game(1024, 672, Phaser.AUTO, 'game');                myGame.state.add('boot', Screen.Boot, true);                myGame.state.add('preloader', Screen.Preloader);                myGame.state.add('gamescreen', Screen.GameScreen);            });        }

Then you can call GameAPI.GameBreak whenever you want to show an ad.

 

 

Thanks, where did you put..

GameAPI.GameBreak.request(this.fnPause, this.fnResume);

?

Link to comment
Share on other sites

I've got some strange behavior going on. I've got this in the preloader

fnResume:function()    {         this.apiTry = true;    },

And I've got this as the update function in the preloader.js

 

update: function () {        if (this.cache.isSoundDecoded('titleMusic') && this.ready == false && this.apiTry == true)        {            this.ready = true;            this.game.state.start('MainMenu');        }}

I know for a fact that fnResume is called because I've put in an alert, and that is displayed correct when the ad is closed, but for some strange reason apiTry never gets seen as true by the if statement in the update function, it's almost as if the fnResume turns off the update function, any ideas?

 

Even when I put

 

this.ready = true;        this.game.state.start('MainMenu');

inside the fnResume function it still doesn't start the main menu....very weird.

Link to comment
Share on other sites

 

Try this:

GameAPI.GameBreak.request(this.fnPause.bind(this), this.fnResume.bind(this));

 

Yay it worked :), what does bind do?

 

Also how do you use

API.Branding.getLogo();

To display their logo? is that meant to automatically put their logo on the screen ? or am I meant use the data included in the returned object somehow?

 

This is the object it's meant to return

{height: 50image : "http://www.url-link-pointing-to-default-image-logo.com/default-logo.png",link  : "http://www.url-link-pointing-to-default-Spil-Games-portal.com",type  : "png",mime  : "image/png",scale : 1style : "margin-left:10%;margin-bottom: 25%;height: 10%;"width : 202}

But how do I use that with Phaser, to create a clickable logo?

Link to comment
Share on other sites

Anyone? just need to know how to use that object data to create a clickable logo in Phaser.

 

If in the preloader you get the logo object and store it somewhere you can get at it. You can use the .url property to get where you need it to link to.

 

On the subject of the API, in the docs there is this paragraph.

 

Info

Branding is controlled at API level: the appropriate branding data is retrieved from the API, depending on the game requirements and based on the contractual agreement between the game developer and Spil Games.

This means that as a game developer you don't need to worry about setting these links: the API provides the appropriate URL values for the necessary branding images and the clickable links.

Therefore, it is important that you don't hardcode any links in your code.

 

At the minute I'm getting the Zibbo branding but A10 is what I need to get. Does the paragraph above mean that it'll be sorted by them on the API level when I deliver?

Link to comment
Share on other sites

  • 3 weeks later...

 

At the minute I'm getting the Zibbo branding but A10 is what I need to get. Does the paragraph above mean that it'll be sorted by them on the API level when I deliver?

 

That's correct, the branding is delivered at run-time.

 

You can test your integration using the Spil test environment which is available at http://cdn.gameplayer.io/testtool/index.html#!/tester. Insert your game endpoint URL (can also be localhost if you prefer) and you're good to go. 

 

If you want to test with the proper branding, you should contact your Licensing contact person, or the Tech support team at http://developers.spilgames.com/contact (use the Support Tab, not the form please!).

 

For reference, the fully updated documentation is available on http://developer.spilgames.com/wiki/Developer_Platform_-_Learning_center_-_HTML5_API_overview

Link to comment
Share on other sites

  • 3 weeks later...

I have a problem with Spil API too. API is loaded correctly, isReady === true, but all methods aren't working correctly. Logo loading for example:

console.log("SpilAPI: ", Main.spilAPI);var logoData = Main.spilAPI.Branding.getLogo();console.log("Logo data: ", logoData);

We can see in console that api is loaded, Branding object available. But getLogo() return strange result - http://imgur.com/Acu4mRl

 

HTML5 test tool shows that everything is ok too. I tested from localhost and from my server. It is not working.

 

Can anyone help please ?

Link to comment
Share on other sites

Hi qdrj,

 

Are you sure the API has been loaded correctly? Was the loadAPI function called and did you pass a function into it, as shown in our tutorial? http://developers.spilgames.com/wiki/Developer_Platform_-_Learning_center_-_HTML5_API_-_%28Tutorial%29_Inclusion

 

This error always occurs when the API is not loaded correctly.

 

If you're in doubt, can you share a code snippet?

 

Thanks.

Link to comment
Share on other sites

Hi qdrj,

 

Are you sure the API has been loaded correctly? Was the loadAPI function called and did you pass a function into it, as shown in our tutorial? http://developers.spilgames.com/wiki/Developer_Platform_-_Learning_center_-_HTML5_API_-_%28Tutorial%29_Inclusion

 

This error always occurs when the API is not loaded correctly.

 

If you're in doubt, can you share a code snippet?

 

Thanks.

Thanks a lot for helping me.

 

I would like to share code but I don't want to show my game in public. So I sent you PM.

 

Hope you don't mind!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...