Quote:
Originally Posted by PawApps
Hello,
Does anyone have any experience with adding Mobclix to a cocos2d app?
I have tried following the advice at this site to no avail. No errors or anything, just no ads.
I'm just starting out, so figuring out the right questions to ask is the first mountain I'm trying to climb.
Thanks all.
|
Generally how it works. I spend hours trying to figure out a problem, then as soon as I post it or ask someone else for help... I get a solution.
For others (I'll be writing a tutorial because there were no good tutorials that I could find) here is the quick and dirty of what I did (lots of thanks to
this thread):
1. Updated AppDelegate.h
Code:
#import "Mobclix.h"
...
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
...
[Mobclix startWithApplicationId:@"mobclix-id-goes-here"];
...
}
2. Here's my HelloWorldLayer.h
Code:
#import "cocos2d.h"
#import "MobclixAds.h"
// HelloWorldLayer
@interface HelloWorldLayer : CCLayer
{
MobclixAdView *adView;
}
// returns a CCScene that contains the HelloWorldLayer as the only child
+(CCScene *) scene;
@property (retain, nonatomic) MobclixAdView *adView;
@end
3. Updated HelloWorldLayer.m
Code:
#import "MobclixAds.h"
...
-(void) onEnter
{
CGSize winSize = [[CCDirector sharedDirector] winSize];
self.adView = [[[MobclixAdViewiPhone_320x50 alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 320.0f, 50.0f)] autorelease];
UIViewController *controller = [UIViewController new];
[controller.view addSubview:adView];
[[[[CCDirector sharedDirector] openGLView] window] addSubview: controller.view];
[self.adView resumeAdAutoRefresh];
[super onEnter];
}
-(void) onExit {
[self.adView pauseAdAutoRefresh];
[adView removeFromSuperview];
[adView release];
[super onExit];
}
That was enough to make an ad show up (error ad until I updated with my mobclix id)
4. My app is landscape, so rotate the ad. I added this directly after [CCDirector .... addSubview:...]
Code:
// Need some landscape ads
CGAffineTransform makeLandscape = CGAffineTransformMakeRotation(M_PI * 0.5f);
makeLandscape = CGAffineTransformTranslate(makeLandscape, 100, 130);
makeLandscape = CGAffineTransformScale(makeLandscape, 0.8f, 0.8f);
adView.transform = makeLandscape;
5. TODO: I still have figure out the best way to make that rotation as well as placement. If I do the rotation the way show above, the CGMakeRect keeps its portrait mode coordinate system.
It is a work in progress. Any pointers would be much appreciated, but at least I have a little bit of results to work off.