How to set two different splash screen in cocos2d v3.x in ios - ios5

I'm working with the cocos2d 3.x and Xcode 5.1.1.I'm having two images image1.png and image2.png.In my game i already change the default image (splash screen) to my image(image1.png).Here i need to display image1.png for 2 seconds and the image2.png to display for next 3 seconds as a splash screen of my game...Thanks in advance..

This is how i do this (to fade in and out a logo, after the default image has been served by iOS. I have a SplashLogo class (a scene). It is my startup scene, it puts up the logo, fades it out, then replaces itself as the running scene with my game controller.
- (void)onEnter {
[super onEnter];
self.positionType = CCPositionTypePoints;
// todo : test this background seed, GL side effects, timing, etc ...
// [self performSelectorInBackground:#selector(seedGameSequencer) withObject:nil];
[self seedGameSequencer];
CCColor *color = [CCColor colorWithRed:0 green:0.f blue:0.f alpha:0.f];
CCNodeColor *black = [CCNodeColor nodeWithColor:color];
black.positionType = CCPositionTypePoints;
black.position = ccp(0, 0);
black.anchorPoint = ccp(0, 0); // bottom left
[self addChild:black];
[GESprite mediumPixelFormat];
CCSprite *logo = [CCSprite spriteWithImageNamed:#"maxPowerStudiosLogo.png"];
logo.positionType = CCPositionTypePoints;
logo.anchorPoint = ccp(.5, .5);
logo.opacity = 0;
logo.positionInPoints = ccp(black.contentSizeInPoints.width / 2, black.contentSizeInPoints.height / 2);
[GESprite defaultPixelFormat];
id fadein = [CCActionFadeIn actionWithDuration:3 * K_FADE_TIME];
id taponne = [CCActionDelay actionWithDuration:.95];
id fadeout = [CCActionFadeOut actionWithDuration:2 * K_FADE_TIME];
id swapSceneAction = [CCActionCallFunc actionWithTarget:self selector:#selector(swapScene)];
id seq = [CCActionSequence actions:fadein, taponne, fadeout, swapSceneAction, nil];
// add the label as a child to this Layer
[self addChild:logo];
[logo runAction:seq];
}
- (void)seedGameSequencer {
mainScene = [MPGameSequencer scene];
}
- (void)swapScene {
[[CCDirector sharedDirector] replaceScene:mainScene];
}
and in AppDelegate :
- (CCScene *)startScene {
// This method should return the very first scene to be run when your app starts.
return [SplashLogo scene];
}

Related

Sprite Kit Coordinates Reversed order

I haven't had this problem before, so I'm wondering if it's a bug.
NSLog(#"%f %f", self.frame.size.height, self.frame.size.width);
is giving me
768.000000 1024.000000
And my app is only set to allow portrait mode. What???
You must be using SpriteKit. You need to make sure to resize the screen by using self.size = self.frame.size; inside your initWithSize:(CGSize)size method of the class you're using (the default would be gameScene).
Essentially:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
self.size = self.frame.size;
// Your code here
};
return self;
}
For Xcode 6 in GameScene.m put this:
-(void)didMoveToView:(SKView *)view {
/* Setup your scene here */
self.size = self.view.frame.size;
}

Putting two backgrounds one after the other in objective-c iphone game?

Hi I am creating an iphone game
in my game layer, I have two identical background images but I want them to go one after the other.
Once the game animal (eg a penguin) crosses the first background, I want the first background to go after the second one-- becoming a continuous background until the game is over.
I have tried everything--- for loops, while loops and such but nothing seems to work
Does anyone have an idea for how I could go about doing this?
Thank you for any help you can provide me.
this is all I have so far after many different tries
- (id) init
{
if((self = [super init]))
{
for ( int x = 0; x < 10000000; ++x)
{
CCSprite *bg = [CCSprite spriteWithFile:#"level1.png"];
[bg setPosition:ccp(160,240)];
ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
[bg.texture setTexParameters:&params];
[self addChild:bg z:0];
CCSprite *bg2 = [CCSprite spriteWithFile:#"level1.png"];
[bg2 setPosition:ccp(320,480)];
ccTexParams param = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
[bg2.texture setTexParameters:&param];
[self addChild:bg z:0];
}
If the backgrounds are the identical you don't actually need 2 images, you can just set the texture rect position of the one and it will continuously move. If you call moveBackground on a timer or in the update method it will continually scroll.
-(void)init
{
if((self=[super init]))
{
background = [CCSprite spriteWithFile:#"background.png"];
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[background.texture setTexParameters:&params];
[self addChild:background z:0];
}
}
-(void)moveBackground
{
// Scroll background 5 pixels to the left
int speed = 5;
background.textureRect = CGRectMake(background.textureRect.origin.x-speed,
background.textureRect.origin.y,
background.textureRect.size.width,
background.textureRect.size.height);
}

Can't load admob ads in view programmatically in my iphone game app

I have an iPhone game app in objective c which uses a private class to load every view programmatically. (without using nib files) I am trying to place an admob ads in the view but it seems I can't have it to work. I tried to place my admob ads view in the init method but still it doesn't load the view.
Here are some codes of how I initialize the data to load the view:
-(id)init
{
if( (self=[super init]))
{
played_ = NO;
KWSprite* background = [KWSprite spriteWithFile:#"title_background.png"];
background.position = ccp(winSize_.width/2, winSize_.height/2);
KWSprite* logo = [KWSprite spriteWithFile:#"logo.png"];
logo.position = ccp(winSize_.width/2, 260);
CCMenuItemImage* start = [CCMenuItemImage itemFromNormalImage:#"start.png" selectedImage:#"start_selected.png" target:self selector:#selector(pressStartButton:)]
CCMenuItemImage* credit = [CCMenuItemImage itemFromNormalImage:#"credit.png" selectedImage:#"credit_selected.png" target:self selector:#selector(pressCreditButton:)];
CCMenuItemImage* iADButton = [CCMenuItemImage itemFromNormalImage:#"noAdsD.png" selectedImage:#"noAdsD#2x.png" target:self selector:#selector(pressiAdButton:)];
CCMenuItemImage* howto = [CCMenuItemImage itemFromNormalImage:#"howto.png" selectedImage:#"howto_selected.png" target:self selector:#selector(pressHowtoButton:)];
CCMenu* menu = [CCMenu menuWithItems:howto, start, credit, iADButton, nil];
[menu alignItemsHorizontally];
menu.position = ccp(winSize_.width/2, 40);
[self addChild:background];
[self addChild:logo];
[self addChild:menu];
}
return self;
}
Looks like you're using Cocos2D here. If you're using a version afte v0.99.5b3, I'd recommend putting your AdMob code within the RootViewController class. It would be better for OpenGL performance since you're not combining your UIKit views with your OpenGL views.
On a high level, you have to add a GADBannerView to your RootViewController's view, then reduce the size of the Cocos2D OpenGL view to make sure the ad shows. What this might look like is below (this code assumes the ad is positioned at the top):
- (void)showBanner {
// Frame of the main RootViewController which we call the root view.
CGRect rootViewFrame = self.view.frame;
// Frame of the main RootViewController view that holds the Cocos2D view.
CGRect glViewFrame = [[CCDirector sharedDirector] openGLView].frame;
// Frame of the GADBannerView
CGRect bannerViewFrame = bannerView_.frame;
CGRect frame = bannerViewFrame;
// The updated x and y coordinates for the origin of the banner.
CGFloat yLocation = 0.0;
CGFloat xLocation = 0.0;
// Move the root view underneath the ad banner.
glViewFrame.origin.y = bannerViewFrame.size.height;
// Center the banner using the value of the origin.
if (UIInterfaceOrientationIsLandscape(toInt)) {
// The superView has not had its width and height updated yet so use those
// values for the x and y of the new origin respectively.
xLocation = (rootViewFrame.size.height -
bannerViewFrame.size.width) / 2.0;
} else {
xLocation = (rootViewFrame.size.width -
bannerViewFrame.size.width) / 2.0;
}
frame.origin = CGPointMake(xLocation, yLocation);
bannerView_.frame = frame;
if (UIInterfaceOrientationIsLandscape(toInt)) {
// The super view's frame hasn't been updated so use its width
// as the height.
glViewFrame.size.height = rootViewFrame.size.width -
bannerViewFrame.size.height;
glViewFrame.size.width = rootViewFrame.size.height;
} else {
glViewFrame.size.height = rootViewFrame.size.height -
bannerViewFrame.size.height;
}
[[CCDirector sharedDirector] openGLView].frame = glViewFrame;
}

Cocos2D iPhone - removing the black screen between CCTransition

I am using cocos2d on my app. I am doing a transition to another scene using
[[CCDirector sharedDirector] replaceScene:
[CCTransitionFadeDown transitionWithDuration:0.5f scene:otherScene]];
On the init part of this other scene, a menu is being built, using CCMenu. This is a full screen menu.
My problem is this: the transition happens to a black screen and then the menu appears. In other words, the transition is being done before the menu is rendered, so, I see an ugly black screen for 0.5 seconds and then, after the transition is done, I see the menu.
To make things clear imagine the first scene has a picture of a boat and the second scene a picture of a car. What I have now is the boat transitioning to black and then the car pops. I need the boat transition to the car.
how do I do that? thanks.
NOTE: I have found this guy with the same problem, but I have tried that solution without success.
This is worth a try, if you are not already using it; it removes black flickers during scene loads. Run the following method before you switch scenes, in case it affects your issue (un-comment these lines and call the method directly):
- (void) removeStartupFlicker
{
//
// THIS CODE REMOVES THE STARTUP FLICKER
//
// Uncomment the following code if you Application only supports landscape mode
//
// CC_ENABLE_DEFAULT_GL_STATES();
// CCDirector *director = [CCDirector sharedDirector];
// CGSize size = [director winSize];
// CCSprite *sprite = [CCSprite spriteWithFile:#"Default.png"];
// sprite.position = ccp(size.width/2, size.height/2);
// sprite.rotation = -90;
// [sprite visit];
// [[director openGLView] swapBuffers];
// CC_ENABLE_DEFAULT_GL_STATES();
}
I have implemented a transition in my menu (same problem), call it 'fadeInView' by adding a black layer on top of everything in the init, with an opacity of 255, and in onEnter I run an action to fade the opacity to 0. as follows:
-(id) init {
self=[super init];
if(self){
// do your stuff
blackShroudLayer_=[CCLayerColor layerWithColor:ccc4(0, 0, 0, 255) width:K_SCREEN_WIDTH height:K_SCREEN_HEIGHT];
[self addChild:blackShroudLayer_ z:500];
}
return self;
}
-(void) onEnter{
// need to [super onEnter] first to that we are running
[super onEnter];
id sh = [CCFadeTo actionWithDuration:K_FADE_TIME opacity:0];
id seq = [CCSequence actions:sh,[CCCallFunc actionWithTarget:self selector:#selector(onUnshroudComplete)], nil];
[blackShroudLayer_ runAction:seq];
}
-(void) onUnshroudComplete{
[blackShroudLayer_ removeFromParentAndCleanup:YES];
}
the constants and blackShroudLayer_ are defined in the class .h file.

cocos2d addChild fails every second time

I have a small game that works perfectly when compiling, howevery every second time I
compile it, it gives me the error:
-(void) addHeroCar{
CGSize screenSize = [CCDirector sharedDirector].winSize;
sprite = [CCBodySprite spriteWithFile:#"carNew.png"];
sprite.world = self;
sprite.physicsType = kDynamic;
sprite.collisionType = kBoxCollisionType;
sprite.collidesWithType = kBoxCollisionType | kWallCollisionType;
sprite.position = ccp(screenSize.width / 2, [sprite boundingBox].size.height / 2);
sprite.density = 0.7f;
sprite.friction = 0.3f;
[sprite addBoxWithName:#"box"];
[self addChild:sprite z:1 tag:HERO_TAG];
sprite.fixed = YES;
}
and the debugger shows me the following errors:
-(void) addChild: (CCNode*) child z:(int)z tag:(int) aTag
{
NSAssert( child != nil, #"Argument must be non-nil");
Im using a cocos2d + box2d wrapper from an other developer, just FYI.
Any suggestions?
Regards,
Mirza