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]。任何人都可以幫我解決這個問題嗎?