0
好吧,我要发布一些代码,以便您可以看到我在做什么,然后最终我会问我的问题。正确缩放纹理
在我的武器类来创建和动画它:
-(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]。任何人都可以帮我解决这个问题吗?