Tengo un CCMenu
con 5 CCMenuItem
s. Cuando el usuario toca un elemento del menú, quiero que el elemento del menú se mueva a la derecha 10 píxeles, para distinguirlo de los demás. Traté de hacer que cada elemento del menú fuera una variable global para poder decir: if (item.isSelected) { [item runAction:blah]; }
Pero esto no hizo nada. Este es mi código hasta ahora:Animación CCMenuItem Cocos2d en la selección
CCLabelTTF *sin = [CCLabelTTF labelWithString:@"Single Player" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item1 = [CCMenuItemLabel itemWithLabel:sin target:self selector:@selector(goToSinglePlayer:)];
CCLabelTTF *spl = [CCLabelTTF labelWithString:@"Splitscreen" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item2 = [CCMenuItemLabel itemWithLabel:spl target:self selector:@selector(goToSplitscreen:)];
CCLabelTTF *ach = [CCLabelTTF labelWithString:@"Achievements" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item3 = [CCMenuItemLabel itemWithLabel:ach target:self selector:@selector(goToAchievements:)];
CCLabelTTF *str = [CCLabelTTF labelWithString:@"Store" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item4 = [CCMenuItemLabel itemWithLabel:str target:self selector:@selector(goToStore:)];
CCLabelTTF *set = [CCLabelTTF labelWithString:@"Settings" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item5 = [CCMenuItemLabel itemWithLabel:set target:self selector:@selector(goToSettings:)];
CCMenu * mainMenu = [CCMenu menuWithItems:item1, item2, item3, item4, item5, nil];
[mainMenu setColor:ccBLACK];
[mainMenu alignItemsVerticallyWithPadding:10];
mainMenu.position = ccp(90, 90);
[self addChild:mainMenu];
if (item1.isSelected) {
[item1 runAction:[CCMoveTo actionWithDuration:1.0f position:ccp(120, 90)]];
}
Mi pregunta es: ¿cómo puedo lograr el efecto que mencioné anteriormente? Quiero que el CCMenuItem
seleccionado se mueva a la derecha de 10 píxeles cuando el usuario lo toca pero no lo suelta, y luego vuelve a su posición normal cuando el toque abandona ese elemento del menú. Además, ¿dónde debería poner este código de animación? En mi función init
? Gracias por la ayuda
Tengo lo mismo y estoy usando un código para que pueda probar ese código. Estoy seguro de que será un buen trabajo para usted. – vishiphone
¿Podría verlo? – Seany242