2012-11-04 99 views
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 

而且Raider.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 

在我的场景,我在中心的对象。我需要将所有物体面向中心旋转,然后我们到达中心旋转它们回到生成点。那么,我如何将我的动画精灵旋转到任何其他精灵的中心? 你可以看到截图如何我们来看一下: enter image description here

+0

第一行是(y = sprite.position.x),第二行是传递两点 - base和你的黄色方块。找到这两条线之间的角度。 – Morion

回答

0

尝试在this so thread

Nikhil的答案,我尝试过了,它完美的作品。只是用一个函数或方法来包装它。