Adding AdMob banners to SpriteKit games

Usually we, indie game developers, need to monetize our creations by showing advertisements but don’t worry, in this tutorial you will learn how to add an AdMob banner to any scene of your games.

This tutorial will consist on three sections:

  • Creating a new AdMob banner
  • Installing Google’s CocoaPod
  • Adding the banner to your game

Note that we are not covering the way to create a new SpriteKit game because you’re supposed to know it before thinking on adding the ads. If not, don’t try to put the cart before the horse. :)

Creating a new AdMob banner

First of all you need to log into AdMob‎ (create a new account if you don’t have one).

Then access the Monetize link on the top menu and then click on the Monetize new app button placed on the top left of the screen.

We are creating the banner for a game that is not on the App Store yet so choose Add your app manually on the following screen and.

Enter My banner game (or your desired game) into App name and choose iOS on Platform and click Add app.

Select Banner as format for the advertisement, edit the style and enter My first banner (or another desired text) as the name of the ad unit before clicking on Save.

After these steps you will find a unit ID (take note of it and keep it close for the future) and a link where you will see how to add the new banner to an iOS app but it doesn’t cover how to add it to your game, which is a little different. Don’t worry you will learn it in the last section of this tutorial.

Installing Google’s CocoaPod

For this purpose you better follow Google’s official guide, which provides the steps to get the resources needed to render the banner on your game.

Adding the banner to your game

Time to code! This is the key step of the process as adding a banner to a game is slightly different than to an app due to the classes used in each of both types of products.

  • Open your game on Xcode (remember to choose the .xcworkspace file) and add the following line to GameScene, just after “import SpriteKit”:

    import GoogleMobileAds

    This way you will be able to use the classes provided by GoogleMobileAds framework.

    Now we can declare a couple of variables that will be useful for our purpose so add the following lines just before the didMoveToView method:

    var viewController: GameViewController!
    var bannerView: GADBannerView!

    With these lines you are declaring a view controller and a GADBannerView, which will render an AdMob banner.

  • Then is time to initialize the banner so, for this purpose, first add the below code at the end of didMoveToView:

    if bannerView == nil {

    And implement this new method with the following lines:

    func initializeBanner() {
    // Create a banner ad and add it to the view hierarchy.
    bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
    bannerView.adUnitID = "ca-app-pub-5767684210972160/3268052334"
    bannerView.rootViewController = viewController

    You are creating a new GADBannerView specifying the smart banner portrait size, which you can modify if you want to show a different kind of banner.

    Then you specify the unit ID that you took note previously and set the root view controller as the one we have declared before.

    Finally you add the banner to the game’s view.

  • Now that the banner is ready you can request an ad so let’s call a new method by adding the following line at the end of didMoveToView:


    And implement it with the following lines:

    func loadRequest() {
    let request = GADRequest()
    request.testDevices = [kGADSimulatorID, "22ed9df524b90565f5e15t23ad232415"]

    You first create a new ad request and then specify the devices you will use to test it (this way you will avoid the possibility of getting penalized by AdMob if you request so much ads during the test process). In above’s example I’m specifying the Xcode simulator and my iPhone’s id, which I got previously by running the game on it.

    Finally you load the new request on the banner view.

  • There is only a left step, which is to initialize the viewController variable we are using. For this purpose go to GameViewController and add the following line before the initialization of the skView constant:

    // Linking view controller and scene to show ads
    scene.viewController = self

    This way you link your game’s view controller to the root of the banner view.

  • If you run the project now you will see something similar to this image:

    Simulator Screen Shot 29 Mar 2016 17.08.00

    And that’s all, you now can load any kind of ads to your games!

    You can find the source code of this tutorial here.


50% Discount extended until 30th April!

Good news! The 50% discount on the Getting Started with SpriteKit book has been extended until April 30th 2016. Don’t lose your opportunity to get the book!

Use the Spritekit50 code or follow this link.

Getting Started with SpriteKit discount


February #1GAM – We made it!

We have published our ‪#‎1GAM‬ February’s game on the App Store! You can find it clicking on the below image:

game_icon copy


Book: Getting Started with SpriteKit

We are glad to announce the publication of the new book written by our collaborator Jorge Jordán: Getting Started with SpriteKit.

This book is the perfect way of start learning how to easily create amazing 2D games with Sprite Kit and Swift, but also you will learn how you can take advantage of Apple’s game engine to highlight your apps.

Its pages teach how to create a beautiful game ready to be published on the App Store, which includes sprite creation and movement, collision detection, running animations, adding labels and life bars to the screen, or implementing the parallax effect.

On the most advanced chapters you will find how to create an initial screen and how to make a transition to the game screen, how to play music and effect sounds, create particle systems, lights and shaders and how to add a tutorial to your game.

In summary, a wonderful book with all you need to make real your own dreams!

One last thing! You can now take advantage of a 50% discount now available 13th April 2016 until 30th April 2016 by clicking on the below image, using the Spritekit50 code or following this link.

Getting Started with SpriteKit discount


One Game a Month – February

During the month of February we have joined a couple of developers and a designer to participate on the One Game A Month challenge.

This month’s word is home and as soon as we knew it we started working on the different ideas provided by each team member. After a couple of days of brain storming we chose the subject of our game and we started giving shape to our idea.

The game is in progress and there is not much to show you but we will share one of the designs you will find in this iOS game we are developing.



Book: 2D iOS & tvOS Games by Tutorials

During the past weeks I’ve had the opportunity of reading one of the latest jobs by my colleagues from, the book: 2D iOS & tvOS Games by Tutorials.

I can’t help to say or write that this title is one of the most brilliants I’ve read from them and it’s not just void words, they are held by tangent reasons.

The book is written for a wide range of spectators: from the most noobs to the experienced ones. If you have never heard about SpriteKit or even wrote a line in Swift (yes, the code of this book is completely written on the last version of this amazing language) you will be able to follow the instructions provided by the book.

On the contrary, if you count with a background on game development you can over-read the first part of the book and start reading the chapters related to advanced game development and tvOS game support. Yes, this title provides detailed explanations on how to develop games for the Apple Tv and how to get rid of the common problems we face when working with the brand new tvOS.


2D iOS & tvOS Games by Tutorials is organised in six main sections which will teach you the following contents progressively:

  • Getting Started: Shows how to create a basic 2D game creating sprites and applying actions and movements to them. In addition it teaches how to build scenes, labels and how to manage the camera. Finally you will also learn how to take advantage of the code developed on this section to port the game for Apple Tv.
  • Physics and Nodes: Introduces the Scene Editor to generate scenes. This section also teaches how to create a game with physics and how to play videos, crop nodes and create shapes. In addition you will also give a step forward on your tvOS knowledge.
  • Juice: Teaches a technique introduced by Apple on the last version of Sprite Kit: state machines, thanks to which we can handle the status of our game easily. It also teaches how to generate particle systems such as explosions and other techniques to create interesting games audio-visually.
  • GameplayKit: Shows how to take advantage of some of the features included this brand new tool which provides support to create pathfinding, agents, goals and provide behaviour to the agents.
  • Advanced Topics: Teaches complementary techniques such as creating tile maps, using the randomisation provided by GameplayKit, how to generate procedural levels or supporting external game controllers.
  • Bonus Chapters: These last pages show some complementary techniques to create a whole product with Game Center achievements and Leaderboards, using the new ReplayKit, how to include advertisement in our games and how to find or create 2d art for our games.

As you can see on the contents above, this book is a must if you want to be on the front of game development, specifically if you want to be one of the first developers creating games for this renovated device: the Apple Tv.


2048 for Apple Watch

We have another game for Apple Watch available on Chupamobile! This time we have created a replica of the addictive game 2048.


Purchase this game template and make your own versions to upload on the App Store!


Simon Says for Apple Watch

Now we also develop games and apps for Apple Watch!

Our first work is a replica of Simon Says. This game bring us back to the 80s with this classic memory training board game.


Try to reproduce what the AI says as far as you can and try to demonstrate that you’re smarter than it.

And now you can also download it on the App Store!


Purchase this game template and make your own versions to upload on the App Store!


Book: Cocos2d games development

Few days ago my first book about Cocos2d games development was released by Packt Publishing: Cocos2d Game Development Blueprints.

It has been a hard but very interesting process which I’ve enjoyed a lot and which gave me the chance to contribute with the game developers community.

What are you going to find in this book? Cocos2d Game Development Blueprints shows how to develop 8 games based on different video games genres such as horizontal scrolling, platforms, tower defense, beat ‘em up, shoot ‘em up, multiplayer cards, quiz, and sports.

The contents on the book are ordered in an increasing difficulty. This way you will learn step by a step from the most easy thing, such as adding a background to your games, to advanced concepts such as kinematic bodies.


In the first chapter you will learn how to create a horizontal scrolling game in which you will add some sprites, backgrounds, sounds and labels. In this game you will try to make the main character (our great friend Joselu the Yeti) avoid some snowballs that are trying to hurt him. For this purpose you will also learn to detect and manage collisions.

The second chapter puts you in the skin of Dr. Nicholas Fringe, a crazy scientific who wants to protect the Earth from the attack of dangerous UFOs with his only two inventions: a laser beam gun and a backpack-reactor. In this chapter you will learn how to implement the parallax effect, to draw geometric primitives, how to use the accelerometer and how to load and set up a particle system.

With the intention of creating a cards game similar to Magic or Hearthstone: Heroes of Warcraft, in chapter three you will learn how to implement a turn-based game integrating Game Center, to implement actions and transform sprites.

Chapter number four is based on one crazy plot: the main character is a zombie in the middle of a human apocalypse and you have to beat all the enemies up to survive. Along this chapter you learn to build a virtual game pad, to animate sprites using multiple image files and how to optimise it by using sprite sheets.

If you continue reading, in the chapter five you will create a quiz game with its tutorial, and how to create transitions between scenes which you will load thanks to external files data.

The following chapter, chapter number six, is a very interesting one. Along theses pages you will learn how to create a game’s physics with bodies, shapes, collisions, and thanks to that you will develop a snooker game.

In chapter seven you will need to help Joselu again. In this case he is in a platform world which you have built thanks to a variety of terrain images, and with custom collision logic. You will also learn how to add a menu to your game.

The final chapter is a classic defend-the-tower game. This is the perfect genre to introduce some AI stuff such as a pathfinding algorithm for the enemies or some smart behaviour for the defenses. In this chapter you will also learn how to predefine positions for the defenses and how to load waves of enemies and share information between nodes.

Ok, I said a lot of things, I will stop writing. Have you realised how cool the cover is? There are more of these amazing designs inside ;).


Romanian MobOS 2015

Past 19th and 20th of February took place the second edition of the Romanian Mobile Operating Systems Conference, also known as MobOS, in the beautiful city of Cluj Napoca (Romania).


It was two days full of interesting talks and workshops subdivided in iOS and Android tracks in which I proudly participate as a speaker together with other nine amazing professionals.

The first day had five presentations per track and I made an overview of Apple’s game development’s frameworks (Sprite Kit and Scene Kit) comparing them with the omnipotent Unity3d.

The following day I addressed one of the two workshops where I showed how to migrate a game from Objective-C to Swift. This way the attendees learnt two things at the same time: how to develop a game with Sprite Kit and how to translate a code written in Objective-C to Swift.


Apart of that knowledge sharing, the organisers of the conference had planned some surprises in the form of amazing giveaways such as an iPod, some wearables and a copy of my book: Cocos2d Game Development Blueprints.

The conference was an absolute success with more than 200 participants, exceeding the initial expectations, and I’m sure MobOS is going to be (if not already) one of the most important conferences on the eastern Europe.

I cannot do other than thank the people from the organisation for making me feel at home, for making real such an amazing event and for giving me the opportunity of trying the papanasi, a typical Romanian dessert :).



« Older posts
%d bloggers like this: