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
在我的場景,我在中心的對象。我需要將所有物體面向中心旋轉,然後我們到達中心旋轉它們回到生成點。那麼,我如何將我的動畫精靈旋轉到任何其他精靈的中心? 你可以看到截圖如何我們來看一下:
第一行是(y = sprite.position.x),第二行是傳遞兩點 - base和你的黃色方塊。找到這兩條線之間的角度。 – Morion