【发布时间】:2010-08-24 16:11:07
【问题描述】:
我正在为 iphone 开发一个应用程序,我是 cocos2d 和 Objective c 的新手。 我在将精灵动画设置为我想要的位置时遇到了一些麻烦。我有一个背景精灵和第二个动画精灵。在这种情况下,背景是一个人,动画精灵是眨眼。
CGSize winSize = [[CCDirector sharedDirector] winSize];
CCSprite * bg = [CCSprite spriteWithFile:@"victory.png"];
[bg setPosition:ccp(240, 160)];
[self addChild:bg z:0];
kidSheetBlinking = [CCSpriteSheet spriteSheetWithFile:@"victory_eyes.png"];
[self addChild:kidSheetBlinking z:0];
// create the sprite
kidSpriteBlinking = [CCSprite spriteWithTexture:kidSheetBlinking.texture rect:CGRectMake(0, 0, 80, 38)];
[kidSheetBlinking addChild:kidSpriteBlinking];
kidSpriteBlinking.position = ccp(winSize.width/2+15,winSize.height/2+62);
// create the animation
kidBlinking1 = [CCAnimation animationWithName:@"blinking1" delay:0.1f];
for (int x = 2; x > 0; x--) {
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:kidSheetBlinking.texture rect:CGRectMake(x*80,0*38,80,38) offset:ccp(0,0)];
[kidBlinking1 addFrame:frame];
}
for (int x = 0; x < 3; x++) {
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:kidSheetBlinking.texture rect:CGRectMake(x*80,0*38,80,38) offset:ccp(0,0)];
[kidBlinking1 addFrame:frame];
}
// create the action
kidBlinkingAction1 = [CCAnimate actionWithAnimation:kidBlinking1 ];
id play = [CCCallFunc actionWithTarget:self selector:@selector(onKidAnimEnd)];
// run the action
[kidSpriteBlinking runAction:[CCSequence actions:kidBlinkingAction1,play, nil]];
胜利的眼睛 png 是 240x38,所以 3 帧是 80x38 对我来说似乎是正确的。但由于某种原因,我无法让动画与其下方的图像正确对齐。精灵动画周围似乎也有一条细线。我已经尝试过多次移动精灵来对齐它,所以这不仅仅是重新定位它的简单问题。我必须错过别的东西。任何想法都会很棒。这是我的第一个应用程序,所以假设我一无所知,任何人都无法想到我可能忽略的任何东西 谢谢 G
【问题讨论】:
标签: iphone objective-c cocos2d-iphone