好的,我将发布一些代码,以便您可以看到我在做什么,然后最后我会问我的问题。
在我的武器类中创建和动画它:
-(id) initWithWeapon
{
// Load the Texture Atlas sprite frames, this also loads the Texture with the same name.
CCSpriteFrameCache *frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"weapon1.plist"];
if ((self = [super initWithSpriteFrameName:@"Gun_image.png"])) {
// create an animation object from all the sprite animation frames
CCAnimation* anim = [CCAnimation animationWithFrame:@"Gun" frameCount:30 delay:0.08f];
// run the animation by using the CCAnimate action
CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];
[self runAction:repeat];
}
self.scale = 0.35f;
return self;
}
这是上面调用的处理动画的方法:
// Creates an animation from sprite frames.
+(CCAnimation*) animationWithFrame:(NSString*)frame frameCount:(int)frameCount delay:(float)delay
{
// load the weapon's animation frames as textures and create a sprite frame
NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];
for (int i = 0; i < frameCount; i++)
{
NSString* file = [NSString stringWithFormat:@"%@%i.png", frame, i];
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
[frames addObject:frame];
}
// return an animation object from all the sprite animation frames
return [CCAnimation animationWithFrames:frames delay:delay];
}
所以我的问题是,当我缩放武器类的实例时(如上图所示 - self.scale = 0.35f),它会缩小到左下角,几乎就像锚点设置为 [0.0,0.0] 而不是[0.5,0.5] 我希望它只是从精灵的中心缩放。我已经输入了一些 NSLogs,它说锚点在 [0.5,0.5]。谁能帮我解决这个问题?