开发者

Cocos2D: Problem Rotating a CCMenu

开发者 https://www.devze.com 2022-12-23 19:33 出处:网络
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

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.


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;

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号