cocos2d动画作为CCMenuItemSprite的子项



我有一个方法:

-(void)myMethod:(id)sender {
    CCMenuItemSprite *anItem = (CCMenuItemSprite *)sender;
    // select animation
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Animation.plist"];
    CCSpriteBatchNode *animationBatchNode = [CCSpriteBatchNode batchNodeWithFile:@"Animation.png"];
    [animationBatchNode addChild:anItem];
    CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"Animation_01.png"];
    [sprite setScaleX: anItem.contentSize.width/sprite.contentSize.width];
    [sprite setScaleY: anItem.contentSize.height/sprite.contentSize.height];
    [sprite setPosition:ccp(anItem.position.x, anItem.position.y)];

    NSMutableArray *animFrames = [NSMutableArray array];
    for(int i = 1; i <= 7; ++i) {
        [AnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Animation_%02d.png", i]]];
    }
    CCAnimation *anim = [CCAnimation animationWithFrames:animFrames delay:0.05f];
    CCActionInterval *animAction = [CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO];
    id seq = [CCSequence actions: animAction, [CCCallFunc actionWithTarget:sprite selector:@selector(removeFromParentAndCleanup:)], [CCCallFunc actionWithTarget:anItem selector:@selector(removeFromParentAndCleanup:)], nil];
    [sprite runAction:seq];
    [anItem addChild:sprite];
}

有人可以帮助我如何正确定位动画吗?现在被放在屏幕上的其他地方,但我想把它放在它的正上方…

使位置相对于菜单的当前位置和大小。类似的东西

[sprite setPosition:ccp(anItem.boundingBox.size.width/2, anItem.boundingBox.size.height + sprite.boundingBox.size.height/2)];

相关内容

  • 没有找到相关文章

最新更新