Spritekit iAds messing with scene size

∥☆過路亽.° 提交于 2019-12-08 03:15:20

问题


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!


回答1:


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.




回答2:


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!




回答3:


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];


来源:https://stackoverflow.com/questions/21873420/spritekit-iads-messing-with-scene-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!