views:

305

answers:

1

If I try to do actions over menuItems but the actions are not running as expected.

I think code below should make the menuItem rotate by 90 degrees but when I run it, the menuItem translates from its coordinates to another coordinate then returns to its original coordinate. The complete translation takes 3 seconds.

What I need is for the menuItem to rotate by 90 degrees in place within a 3 seconds duration. Please explain where I have done wrong?

CCMenuItemImage *targetE;//Globally declared
CCMenu *menu;//Globally declared

-(id)init
{
    if( (self = [super init]) )
    {
        isTouchEnabled = YES;
        CGSize windowSize = [[CCDirector sharedDirector] winSize];
        targetE = [CCMenuItemImage itemFromNormalImage:@"grossinis_sister1.png"     selectedImage:@"grossinis_sister1.png" target:self selector:@selector(touch:)];

        menu = [CCMenu menuWithItems:targetE,nil];
        id action4 = [CCRotateBy actionWithDuration:3.0 angle:90];
        [menu runAction: [CCSequence actions: action4, nil]];
        menu.position = ccp(windowSize.width/2 + 200, windowSize.height/2); 
        [self addChild: menu z:10];
    }
    return self;
}
@end

Thank You.

A: 

If you want to rotate a single menu item (like in your example) just run CCRotateBy action on CCMenuItem:

[targetE runAction:action4];

If you want to rotate the whole menu with all its menu items then you have to consider its contentSize, anchorPoint and position. In your case the easiest way to rotate the menu in place is to set its contentSize to zero.

menu.contentSize = CGSizeZero;

lechec