Build 10 games and learn game development along the way in this fast paced game development course

Get the source code of 12 commercial games, loaded 50+ million times, and learn the secrets of game design

Learn how to make a successful Flash game from a real world example. Fully commented source code

Create realistic Flash physics games from scratch with advanced features, from Angry Birds to Crush the Castle

How to add interlevel ads to your PuzzleScript HTML5 games

I really like PuzzleScript engine because it allowed me to create an 80 levels Sokoban game in a few minutes, then I was able to add mobile controls to play it on mobile devices.

Now, what about trying to monetize your PuzzleScript games? I am showing you a quick way to insert interlevel ads.

In my example I am using Google Adsense, but you are free to place the ad you prefer, or even choose which ad network to display according to level number or other variables.

This is the result:

You can play the game at http://www.emanueleferonato.com/stuff/bwban_mobile/.

Let’s see how it’s done:

First, in your HTML, add these lines somewhere between <body> and </body>:

Now it’s time to add a bit of style to adcontainer, ad and closead divs:

What’s next? We have to place into PuzzleScript generated code a function to call whenever we want to display an ad. Search for loadLevelFromState function declaration and at the very beginning of the function add:

function loadLevelFromState(a,b){showAd(b),forceRegenImages=!0,}

Now every time a new level (or a new message) is about to be displayed, we’ll call showAd function with the level (or message) number passed as argument.

This is showAd function:

I am simply showing the ad when the level is greater than zero and can be divided by two. That’s because I have a message before each level, and I want the ad to be displayed when the game shows the message, so at level 2, 4, 6, and so on.

To close the ad, use:

And that’s it, now you can have some kind of interlevel ads.

Download the full project

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 3.50 out of 5)
Loading ... Loading ...
Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 3 comments

  1. How to add interlevel ads to your PuzzleScript HTML5 games | Adobe

    on December 3, 2013 at 9:07 pm

    [...] Emanuele Feronato With PuzzleScript you can create great HTML5 games in a few minutes, now I am showing you how to [...]

  2. CoderGuy

    on December 6, 2013 at 10:06 am

    Nice article, the PuzzleScript engine is great!

  3. Marcio Andrey Oliveira

    on December 31, 2013 at 7:19 pm

    Thank you for sharing this. It will be very useful.

    But I have a doubt: one can’t use regular Adsense ads for Flash games. Otherwise one will be banned from Google Adsense.

    Are we allowed to use Adsense ads on HTML5 games?

Thank you for the download!!

I hope you will find it useful and make something interesting out of it

To keep up to date with the blog, why don't you like my Facebook page and follow me on Twitter?

Want to learn more? Don't miss this:

Learn how to make a successful commercial Flash game from a real world example: get the fully commented source code of Globez, a Flash game played millions of times which generated a four figure income. Limited copies available.

Get it now

×