I'm writing some code for a Menu using AtlasSprites where the items appear one by one, and are set to enabled as they appear. However, called [item setIsEnabled:YES]; causes the items to actually disappear one by one. As a test, I removed any code referring to the visible property. The items disappear one by one. When I remove the call to setIsEnabled, the items don't disappear anymore. Anyone know what gives? Thanks
MenuItemAtlasSprite: setIsEnabled causes sprite to disappear?
(7 posts) (3 voices)-
Posted 2 years ago #
-
how are you initializing your items? can you post some code?
Posted 2 years ago # -
Here is the initialization code, which is located in the init function for a layer subclass. MenuItemMeta is a subclass of MenuItemAtlasSprite, which I use to play sounds and simulate a button press effect. So, I use the same sprite for all three image states.
asm = [AtlasSpriteManager spriteManagerWithTexture:[[TextureMgr sharedTextureMgr] addImage:@"grid-flat.png"] capacity:2];
asm.blendFunc = (ccBlendFunc) { GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA };
[asm setPosition:ccp(60,160)];
[self addChild:asm z:0];again = [AtlasSprite spriteWithRect:CGRectMake(746,177,118,22) spriteManager:asm];
again.anchorPoint = ccp(0,.5f);
[asm addChild:again];achieve = [AtlasSprite spriteWithRect:CGRectMake(486,177,260,23) spriteManager:asm];
achieve.anchorPoint = ccp(0,.5f);
[asm addChild:achieve];againItem = [[MenuItemMeta itemFromNormalSprite: again
selectedSprite: again
disabledSprite: again
target: [HallwayManager sharedHallwayManager]
selector: @selector(againTap:)] retain];achieveItem = [[MenuItemMeta itemFromNormalSprite: achieve
selectedSprite: achieve
disabledSprite: achieve
target: [HallwayManager sharedHallwayManager]
selector: @selector(achieveTap:)] retain];[againItem setIsEnabled:NO];
[achieveItem setIsEnabled:NO];menu = [Menu menuWithItems:againItem, achieveItem, nil];
[menu alignItemsVertically];
[menu setPosition:ccp(60,160)];
[self addChild:menu z:0];
Posted 2 years ago # -
try creating 3 different atlas sprites, instead of just the one. It might not be the cause, but I seem to remember having an issue sharing the same sprite for different menu item states in the past.
Posted 2 years ago # -
Thanks Phil, that seems to have done the trick! Though actually, since declaring three identical AtlasSprites is wasteful, what I really needed to do was declare them as NULL. If I declare them as either discrete AtlasSprites or as NULL, it works fine. The only problem comes from trying to use the same AtlasSprite for more than one.
Which actually makes sense first thing in the morning rather than at the end of a long day!
Posted 2 years ago # -
cool, didn't know you could use NULL there, that's useful to know!
Posted 2 years ago # -
Actually, it seems that maybe you can't use NULL for those values. It causes them not to be displayed when selected/ disabled.
MenuItemAtlasSprite seems to be very buggy. I'm having nothing but problems with it, and I don't have to use it for performance, so I'm switching back to MenuItemSprite.
Things that seem to cause problems with MenuItemAtlasSprite:
- The documentation says keep the AtlasSpriteManager and Menu at the same coordinates. but the menu actually seems to need double the x value of the ASM to line up right.
- alignItemsVerticallyWithPadding causes the items to appear on top of one another (that is, at the same exact position), even if the padding value is set to very large number such as 100.
- aforementioned problems regarding using the same AtlasSprite for more than one position, or trying to bypass setting a state. I thought that setting a state's image to nil was supposed to make the MenuItem use its Normal state instead?Posted 2 years ago #
Reply
You must log in to post.