CCMenuItemImage and CCMenuItemSprite have offset selectedSprite

CCMenuItemImage and CCMenuItemSprite have offset selectedSprite
0.0 0


Easiest repro is to run HelloWorld. When you click on the close sprite, and CloseSelected.png is rendered, it is “offset” to the upper-right rather than being centered. It seems as though both CloseNormal and CloseSelected are anchored via their lower-left rather than their center. (But CloseNormal does seem initially positioned based on its center.)

Is this a bug? Or, if not, how are people dealing with it? It seems the 99.9% use case would be for the images to both be centered based on the position set to ::setPosition.


Yeah, I agree, it’s a bit odd.
I just test cocos2d-iphone edge code on its’ develop branch, the behavior is the same.
Considering the porting games, I wouldn’t like to change the logic here. You can post in cocos2d-iphone forum, or pull a fix to cocos2d-iphone github repo to see if our parent project will fix it.

I test this code in cocos2d-iphone new project

@implementation HelloWorldLayer

// on "init" you need to initialize your instance
-(id) init
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super" return value
    if( (self=[super init])) {

        // ask director the the window size
        CGSize size = [[CCDirector sharedDirector] winSize];

        CCMenuItemImage *closeItem = [CCMenuItemImage itemFromNormalImage:@"CloseNormal.png"
        closeItem.position = ccp(size.width/2, size.height/2);

        CCMenu* menu = [CCMenu menuWithItems:closeItem, nil];
        menu.position = CGPointZero;

        // add the label as a child to this Layer
        [self addChild: menu];
    return self;


Cool, just now posted on the iPhone forum:

Understood about keeping in step as a pure port of the Objective-C version. I don’t actually use the Objective-C version, so worst case, I’ll fix it in the C++ code and post the fix on the iPhone forum, with hopes that they translate the fix. I’m surprised this bug wasn’t brought up before given that it’s in HelloWorld, and every user that uses a different image size for the selected and normal images would see this problem.