Closed GoogleCodeExporter closed 9 years ago
I had the same problem, so I changed MenuItemSprite to properly draw the
children.
Attached is the patch (based off latest trunk r1307).
Original comment by myBuddyCJ@gmail.com
on 25 Aug 2009 at 4:57
Attachments:
Original comment by ricardoq...@gmail.com
on 27 Aug 2009 at 1:17
to be addressed with the new sprite refactoring in v0.9
Original comment by ricardoq...@gmail.com
on 5 Oct 2009 at 6:48
Original comment by ricardoq...@gmail.com
on 8 Feb 2010 at 4:21
Original comment by ricardoq...@gmail.com
on 8 Feb 2010 at 4:24
Original comment by ricardoq...@gmail.com
on 19 Mar 2010 at 10:48
Original comment by ricardoq...@gmail.com
on 24 Apr 2010 at 2:12
Original comment by ricardoq...@gmail.com
on 26 May 2010 at 6:20
Original comment by ricardoq...@gmail.com
on 14 Jul 2010 at 9:48
Issue 990 has been merged into this issue.
Original comment by ricardoq...@gmail.com
on 24 Oct 2010 at 3:34
fixed
http://github.com/cocos2d/cocos2d-iphone/commit/efdcb3ac13ca86f9161b825ab45cf626
fc0be7c2
Original comment by ricardoq...@gmail.com
on 2 Nov 2010 at 7:36
Still not working complete (at least not for me).
The children are being drawn fine now however there's no way to click the
button (even the selected: item doesn't work).
In my case, I subclassed CCSprite and added a few elements (CCColorLayer, some
CCSprites and a CCLabel). The CCSprite itself doesn't have any images or
anything - just children.
Original comment by nedraf...@gmail.com
on 3 Nov 2010 at 1:52
@nedrafehi: Could you attach a test case ? Thanks.
reopened.
Original comment by ricardoq...@gmail.com
on 3 Nov 2010 at 3:00
[deleted comment]
Here is the actual test code (just copy into a black scene) and it should work.
The actual class and images used are attached.
// 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];
QuestionContainerSprite* question = [[QuestionContainerSprite alloc] init];
QuestionContainerSprite* question2 = [[QuestionContainerSprite alloc] init];
CCMenuItemSprite* sprite = [CCMenuItemSprite itemFromNormalSprite:question2 selectedSprite:question target:self selector:@selector(selectAnswer:)];
CCColorLayer* layer = [CCColorLayer layerWithColor:ccc4(0,0,255,255) width:100 height:100];
CCColorLayer* layer2 = [CCColorLayer layerWithColor:ccc4(255,0,0,255) width:100 height:100];
CCMenuItemSprite* sprite2 = [CCMenuItemSprite itemFromNormalSprite:layer selectedSprite:layer2 target:self selector:@selector(selectAnswer:)];
CCMenu* menu = [CCMenu menuWithItems:sprite, sprite2, nil];
[menu alignItemsVerticallyWithPadding:100];
[menu setPosition:ccp(size.width / 2, size.height / 2)];
// add the label as a child to this Layer
[self addChild: menu];
}
return self;
}
-(void)selectAnswer:(id)sender
{
CCLOG(@"Selected");
}
Original comment by nedraf...@gmail.com
on 3 Nov 2010 at 4:23
Attachments:
workaournd:
Set the contentoSize of QuestionContainerSprite before adding it into the
MenuItem.
eg:
[question setContentSize: size_of_children];
I'll mark this bug as fixed, since the original bug is fixed.
Please, open a new bug if you want that the menu automatically tests
"collision" with its children.
Original comment by ricardoq...@gmail.com
on 3 Nov 2010 at 8:19
Benihana test code does not work before and after the fix for different reasons:
CCSprite *tempSprite = [CCSprite spriteWithFile:@"Icon.png"];
[tempSprite addChild:[CCSprite spriteWithFile:@"fps_images.png"] z:1];
CCMenuItem *thisMenuItem = [CCMenuItemSprite itemFromNormalSprite:tempSprite
selectedSprite:tempSprite]; // SIGABORT
CCMenu *thisMenu = [CCMenu menuWithItems:thisMenuItem, nil];
[self addChild:thisMenu];
But this one is ok:
CCSprite *tempSprite = [CCSprite spriteWithFile:@"Icon.png"];
[tempSprite addChild:[CCSprite spriteWithFile:@"fps_images.png"] z:1];
CCSprite *tempSprite1 = [CCSprite spriteWithFile:@"Icon.png"];
[tempSprite1 addChild:[CCSprite spriteWithFile:@"fps_images.png"] z:1];
CCMenuItem *thisMenuItem = [CCMenuItemSprite itemFromNormalSprite:tempSprite
selectedSprite:tempSprite1]; // ok
CCMenu *thisMenu = [CCMenu menuWithItems:thisMenuItem, nil];
[self addChild:thisMenu];
Original comment by a1rex2...@gmail.com
on 5 Nov 2010 at 12:29
Original issue reported on code.google.com by
ricardoq...@gmail.com
on 22 Jul 2009 at 4:24