1

我有我的动画精灵:

   #import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface Raider : CCSprite
{
    NSUInteger baseX;
    NSUInteger baseY;
    BOOL takeItem;
    CCAction *_walkAction;
    CCAction *_moveAction;
    CCAnimation *walkAnim;
}

@property (nonatomic) NSUInteger baseX;
@property (nonatomic) NSUInteger baseY;
@property (nonatomic) BOOL takeItem;
- (id) initRaider:(NSUInteger)x andY: (NSUInteger)y;
- (void) setTaken;
@property (nonatomic, retain) CCAction *walkAction;
@property (nonatomic, retain) CCAction *moveAction;
@property (nonatomic, retain) CCAnimation *animation;

-(void)stopAnim;
-(void)startAnim;

@end

还有攻略.m

#import "Raider.h"

@implementation Raider
@synthesize baseX;
@synthesize baseY;
@synthesize takeItem;
@synthesize moveAction = _moveAction;
@synthesize walkAction = _walkAction;
@synthesize animation = walkAnim;

- (id) initRaider:(NSUInteger)x andY: (NSUInteger)y
{
    [self initWithFile:@"10001.png"];
    self.walkAction = nil;
    self.animation = nil;
    self.position = ccp(x,y);
    baseX = x;
    baseY = y;
    takeItem = NO;

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"pirate.plist"];
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 9; ++i)
    {
        [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
                                   [NSString stringWithFormat:@"1000%d.png", i]]];
    }
    self.animation = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
    self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
    [self runAction:_walkAction];
    return self;
}

- (void) setTaken
{
    [self setTexture:[[CCTextureCache sharedTextureCache] addImage:@"raiderItem.png"]];
}

-(void)stopAnim
{
    [self pauseSchedulerAndActions];
}

-(void)startAnim
{
    [self resumeSchedulerAndActions];

}

@end

在我的场景中,我在中心有一个物体。我需要将所有对象面向中心旋转,然后我们将它们到达中心旋转它们回到生成点。那么,如何将动画精灵旋转到任何其他精灵的中心?您可以看到屏幕截图现在的样子: 在此处输入图像描述

4

0 回答 0