开发者

CCMenu doesnt work in iPad

I'm creating an universal application and my CCMenu appears just fine on both iPhone, iPhone 4 and iPad. However the buttons do nothing when touched on the iPad.

I have no specific iPad code other than modifying the contentScaling property so that the iPad uses the same images as the iPhone 4. This means that the same images work on iPhone 4 but not on the iPad.

I am using cocos2d 0.99.rc0 and the iOS 4.1 SDK. I don't even know where to start troubleshooting this.

The only oddity i noticed recently is that the iPad seems to draw the menu scene once, then quickly redraws it for some reason, moving everything one pixel or something. My menu class is very simple and has no "refreshing" code or anything that is supposed to move. This doesnt happen on either low or high res iPhones.

Here is my code, sloppy but yet very simple.

MainMenu.m:

    CCMenuItemImage * playItem = [self makeMenuButtonWithSprite:@"Play.png" withSelector:@selector(play:)];

    CCMenuItemImage * resumeItem = [self makeMenuButtonWithSprite:@"Resume.png" withSelector:@selector(resume:)];

    CCMenuItemImage * optionsItem = [self makeMenuButtonWithSprite:@"Options.png" withSelector:@selector(options:)];

    CCMenuItemImage * helpItem = [self makeMenuButtonWithSprite:@"Help.png" withSelector:@selector(help:)];

    CCMenu *myMenu;

    // Check if there is a valid savegame by comparing versions.
    if ([[uD stringForKey:@"CFBundleVersion"] isEqualToString:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBund开发者_StackOverflow社区leVersion"]] ) {
        myMenu = [CCMenu menuWithItems:playItem, resumeItem, optionsItem, helpItem, nil];
    } else {
        myMenu = [CCMenu menuWithItems:playItem, optionsItem, helpItem, nil];
    }

    // Arrange the menu items vertically
    [myMenu alignItemsVerticallyWithPadding:0.0f];
    myMenu.position = ccp(dB.wWidth/2,dB.wHeight/2);

    // add the menu to your scene
    [self addChild:myMenu z:100];

And the CCMenuItemImage factory:

- (CCMenuItemImage *)makeMenuButtonWithSprite:(NSString *)spriteFileName withSelector:(SEL)selector {
    CCSprite *spriteForButton = [CCSprite spriteWithFile:spriteFileName];
    spriteForButton.anchorPoint = ccp(0.5f,0.5f);
    CCMenuItemImage * buttonImage =[CCMenuItemImage itemFromNormalImage:@"button.png"
                                                      selectedImage: @"button.png"
                                                             target:self
                                                           selector:selector];
    [buttonImage addChild:spriteForButton z:100];
    spriteForButton.position = ccp([buttonImage boundingBox].size.width/2,([buttonImage boundingBox].size.height/2)-5);
    return buttonImage;
}


I don't think that any known bug exists for this issue. Not sure how to debug this without seeing any code, but, if it helps, here's some code of mine that successfully adds a menu using cocos2d 0.99.5, on iOS 4.0, 4.1 and 4.2 (no difference when I upgraded):

-(void) initBottomMenu {
CCMenuItem *aboutButton = [self gameButtonWithName:@"about" selector:@selector(onAbout:)];
CCMenuItem *settingsButton = [self gameButtonWithName:@"settings" selector:@selector(onSettings:)];
CCMenuItem *tutButton = [self gameButtonWithName:@"tutorial" selector:@selector(onTutorial:)];

CCMenu *menu = [CCMenu menuWithItems:aboutButton, settingsButton, tutButton, nil];
menu.position = ccp(xPos, yPos);

[menu alignItemsHorizontallyWithPadding:45.0];

[self addChild:menu];
}

The gameButtonWithName:selector: method looks like this:

-(CCMenuItem *) gameButtonWithName:(NSString *)name selector:(SEL)s {

NSString *iPadSuffix = @"IPad";

NSString *normal    = [[NSString alloc] initWithFormat:@"%@Btn%@.png", name, iPadSuffix, nil]   ;
NSString *selected  = [[NSString alloc] initWithFormat:@"%@Btn%@.png", name, iPadSuffix, nil];

CCMenuItem *retButton = [CCMenuItemImage itemFromNormalImage:normal
                                               selectedImage:selected
                                               disabledImage:selected
                                                      target:self
                                                    selector:s];

[selected release];
[normal release];

return retButton;
}

sort of sloppy, but it works out well for adding a menu to my main scene.


Problem found. This was related to my custom hack to make the iPad load retina graphics. The problem was in my appDelegate where i set the contentScaleFactor which made ccDirector scale and UIScreen scale mismatch.

Problem boiled down to graphics being big but cocos2d thinking that coordinates are low res.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜