Maccle415
Maccle415

Reputation: 222

Spritekit iAds messing with scene size

I am making a game using spritekit and everything works perfectly except when I add the code to add an iAd. When I add the iAd everything works but it seems that the iAd is resizing the scene when it is being displayed.

This is my code to display the iAd, it is in the ViewController.m :

 #import <iAd/iAd.h>
 #import "ViewController.h"
 #import "MainMenu.h"


 @implementation ViewController

 - (void)viewDidLoad
 {
     [super viewDidLoad];

     // Configure the view.
     SKView * skView = (SKView *)self.originalContentView;
     skView.showsFPS = YES;

     // Create and configure the scene.
     SKScene * scene = [MainMenu sceneWithSize:skView.bounds.size];
     scene.scaleMode = SKSceneScaleModeAspectFill;

     self.canDisplayBannerAds = YES;

     // Present the scene.
     [skView presentScene:scene];
 }

Like I say, the iAd shows up, and all the function properly but the when the iAd is displayed it makes the scene smaller, is there a method or something that allows the scenes to not be resized?

An help is much appreciated, thanks!

Upvotes: 1

Views: 903

Answers (3)

user5173251
user5173251

Reputation: 21

There is another way to fix this problem. You might want to have a look at this Thread.

iAd in Spritekit

Just a sneak preview:

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.delegate = self;
[adView setFrame:CGRectMake(0, 0, 1024, 768)]; // set to your screen dimensions
[adView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:adView];

Upvotes: 0

DKLA
DKLA

Reputation: 243

Just a thought, but you could also put the AdBannerView in via the Storyboard editor, and then set

self.canDisplayBannerAds = NO;

That way it will just overlay the SKScene instead of shrinking it.

Hope this helps!

Upvotes: 0

Maccle415
Maccle415

Reputation: 222

Ok so I sort of figured it out, I was using scaleMode of SKSceneScaleModeAspectFit I have now changed it to SKSceneScaleModeFill this seems to make the scene shorter but it is not as noticeable as the aspectFit scale mode. I have also noticed that the iAd does not act like a sprite as it actually distorts or resizes the screen. If anyone knows how to create the iAd on top of the view, like sprite, please add a comment or solution.

EDIT

I have just figured out that one can add an ADBannerView to the viewcontroller in the interface builder, this will show the ad on all scenes. I am now trying to figure out how this can be set to not display on specific scenes seeing spritekit only uses one viewcontroller.

If you add the ad by adding in the AdBannerView then you have to create seperate methods in the view controller to turn the ads on or off, by creating these seperate methods it allows one to have manual control over the ads in the view controller from any scene.

In the view controller you have a scene that you create, this scene variable/object has a property of tag or userdata. So if your game goes to a different scene you can call

[super scene] setTag:x]

Every time that the NSTimer calls my control method it checks the value of the scenes tag in the view controller and based on that value it will remove or re-display the ad.

Upvotes: 3

Related Questions