0

I have an image that loads on a MainMenu scene and appears as wrong sized when the game launches but then after finishing a level returns you to the MainMenu again the image appears right sized.

The first time the image appears to be three quarters or 4/5 of the size of the screen from left to right. The image has a white background around it so I can see a black tall rectangle in the right side of the screen on the main menu's first launch. But after a game it is sized properly and the white background image is sized properly.

Anybody ever have this happen?

Here is the init code for the MainMenuLayer:

-(id)init {
    if( (self=[super initWithColor:ccc4(255,255,255,255)]) ) {
        [[GameManager sharedGameManager] playBackgroundTrack:BACKGROUND_TRACK_MAIN_MENU];
        CGSize screenSize = [CCDirector sharedDirector].winSize;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            CCSprite *background = [CCSprite spriteWithFile:@"MainMenu-iPad.png"];
            [background setPosition:ccp(screenSize.width/2,screenSize.height/2)];
            [self addChild:background];
            [self displayMainMenu];
        } else {
            CCSprite *background = [CCSprite spriteWithFile:@"MainMenu.png"];
            [background setPosition:ccp(screenSize.width/2,screenSize.height/2)];
            [self addChild:background];
            [self displayMainMenu];
        }
-

It works fine on the simulator though...

marciokoko
  • 4,988
  • 8
  • 51
  • 91

2 Answers2

1

Print screen position, if position is wrong then put you code in onEnter instead of init.

See this thread in Stack overflow.

-(id)init {
    if( (self=[super initWithColor:ccc4(255,255,255,255)]) ) {
       }
     return self;
}



-(void)onEnter {
        [super onEnter];
        [[GameManager sharedGameManager] playBackgroundTrack:BACKGROUND_TRACK_MAIN_MENU];
        CGSize screenSize = [CCDirector sharedDirector].winSize;

         CCSprite *background = [CCSprite spriteWithFile:@"MainMenu.png"];
         [background setPosition:ccp(screenSize.width/2,screenSize.height/2)];
         [self addChild:background];
         [self displayMainMenu]; 
}
Community
  • 1
  • 1
Guru
  • 21,652
  • 10
  • 63
  • 102
  • Well I did this but I still get the image wrong-sized. :(. Why would it only happen on launch and not after its loaded a second time? – marciokoko Feb 26 '13 at 18:16
  • print image size. For hd, placed hd image? – Guru Feb 26 '13 at 18:37
  • i have all 4 sized images: 480x320, 960x640, 1024x768, 2048x1536 for png, -hd.png, -iPad.png and -iPad-hd.png respectively. It works for other devices and like i said, it works fine after a second run. Its just the first run thats messing things up. – marciokoko Feb 26 '13 at 19:52
  • im printing image size, by doing background.contentSize.height and width, and i get 1024 x 768 for all idiomiPads and 480x320 for all iPhones. – marciokoko Feb 28 '13 at 16:47
  • instead of -iPad.png put -ipad.png and -iPad-hd.png to -ipadhd.png, in code as well as in image in disk. That must work...and no need to specify hd image in code....it takes... – Guru Feb 28 '13 at 18:45
  • ok but all my other images are -iPad & -iPad-hd. And they work fine. Furthermore, this very image works fine after ive gone through the main menu once and played a game level and then return to the main menu. Its just the first time the mm runs that it has that problem. – marciokoko Feb 28 '13 at 20:21
0

The image was apparently being cached even after clean and build! I ended up replacing the image by removing the original and adding the same one but with some markers just to make sure it got replaced.

marciokoko
  • 4,988
  • 8
  • 51
  • 91