一张图片胜过千言万语。这是我的:
上图描绘了两个精灵, 中间右边的那个是玩家,中间左边的那个是AI玩家。 它们的两个初始化都使用相同的superClass。我们应该看到类似的质量精灵。
然而,正如你所看到的,正确的精灵在某种程度上是扭曲的。我还注意到来自同一个spriteSheet的其他精灵的斑点出现在一些动画帧的上方和下方。 玩家精灵上没有进行任何转换。除了那些也在ai精灵上执行的动作之外,没有任何动作可以运行。
还有其他人遇到过这个吗?我甚至不确定如何说出这个问题;) 还有其他问题吗?请问!
详细说明: 我正在使用Cocos2d 1.0.0 ..在Lion上运行Xcode 4.1。
代码示例: 此代码在包含CCFiniteTimeActions的NSObject初始化之后运行,并且 一个CCSprite
NSMutableArray *ww1 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww1 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_left%d.png", string, i]]];
}
CCAnimation* aa1 = [CCAnimation animationWithFrames:ww1 delay:0.1f];
walkLeft = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:aa1 restoreOriginalFrame:NO]];
//RIGHT
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_right%d.png", string, i]]];
}
CCAnimation *aa2 = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
walkRight = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:aa2 restoreOriginalFrame:NO]];
//UP
NSMutableArray* ww2 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww2 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_up%d.png", string, i]]];
}
CCAnimation* aa3 = [CCAnimation animationWithFrames:ww2 delay:0.1f];
walkUp = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:aa3 restoreOriginalFrame:NO]];
//DOWN
//walkAnimFrames = nil;
//walkAnimation = nil;
NSMutableArray* ww3 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww3 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_down%d.png", string, i]]];
}
CCAnimation* aa4 = [CCAnimation animationWithFrames:ww3 delay:0.1f];
walkDown = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:aa4 restoreOriginalFrame:NO]];
//ATTACK ANIMATIONS
animation = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"%@_down0.png", string] ];
NSMutableArray* ww4 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww4 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_left_attack%d.png", string, i]]];
}
CCAnimation *qq0 = [CCAnimation animationWithFrames:ww4 delay:0.1f];
meleeLeft =
[CCAnimate actionWithDuration:0.4 animation:qq0 restoreOriginalFrame:NO];
//RIGHT
NSMutableArray* ww5 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww5 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_right_attack%d.png", string, i]]];
}
CCAnimation *qq1 = [CCAnimation animationWithFrames:ww5 delay:0.1f];
meleeRight =
[CCAnimate actionWithDuration:0.4 animation:qq1 restoreOriginalFrame:NO];
//UP
NSMutableArray* ww6 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww6 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_up_attack%d.png", string, i]]];
}
CCAnimation *qq2 = [CCAnimation animationWithFrames:ww6 delay:0.1f];
meleeUp =
[CCAnimate actionWithDuration:0.4 animation:qq2 restoreOriginalFrame:NO];
//DOWN
NSMutableArray* ww7 = [NSMutableArray array];
for(int i = 0; i <= 3; ++i) {
[ww7 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_down_attack%d.png", string, i]]];
}
CCAnimation *qq3 = [CCAnimation animationWithFrames:ww7 delay:0.1f];
meleeDown =
[CCAnimate actionWithDuration:0.4 animation:qq3 restoreOriginalFrame:NO];
//****DEATH ANIMATIONS
NSMutableArray* ww8 = [NSMutableArray array];
for(int i = 0; i <= 7; ++i) {
[ww8 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_left_die%d.png", string, i]]];
}
CCAnimation *qq4 = [CCAnimation animationWithFrames:ww8 delay:0.05f];
deathLeft =
[CCAnimate actionWithDuration:0.4 animation:qq4 restoreOriginalFrame:NO];
//RIGHT
NSMutableArray* ww9 = [NSMutableArray array];
for(int i = 0; i <= 7; ++i) {
[ww9 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_right_die%d.png", string, i]]];
}
CCAnimation *qq5 = [CCAnimation animationWithFrames:ww9 delay:0.05f];
deathRight =
[CCAnimate actionWithDuration:0.4 animation:qq5 restoreOriginalFrame:NO];
//UP
NSMutableArray* ww10 = [NSMutableArray array];
for(int i = 0; i <= 7; ++i) {
[ww10 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_up_die%d.png", string, i]]];
}
CCAnimation *qq6 = [CCAnimation animationWithFrames:ww10 delay:0.05f];
deathUp =
[CCAnimate actionWithDuration:0.4 animation:qq6 restoreOriginalFrame:NO];
//DOWN
NSMutableArray* ww11 = [NSMutableArray array];
for(int i = 0; i <= 7; ++i) {
[ww11 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"%@_down_die%d.png", string, i]]];
}
CCAnimation *qq7 = [CCAnimation animationWithFrames:ww11 delay:0.05f];
deathDown =
[CCAnimate actionWithDuration:0.4 animation:qq7 restoreOriginalFrame:NO];
[sprites addChild:animation];
[walkRight retain];
[walkLeft retain];
[walkUp retain];
[walkDown retain];
[meleeDown retain];
[meleeUp retain];
[meleeLeft retain];
[meleeRight retain];
[deathUp retain];
[deathRight retain];
[deathDown retain];
[deathLeft retain];
[self setDir:newFacing];
变量“sprites”是指向CCSpriteBatchNode的指针。我确信他们指向同一个批处理节点,因为只有一个。
如您所见,此对象通过批处理节点将自己的动画添加到图层。
我将发布移动发生的方法:
moveAction = [CCMoveTo actionWithDuration:0.3 position:ccp(thisDoodad.newX, thisDoodad.newY)];
if (thisDoodad.animation.visible == NO) {
id beingVisible = [CCCallFunc actionWithTarget:thisDoodad
selector:@selector(makeVisible)];
id seq = [CCSequence actions: moveAction, beingVisible, nil];
[thisDoodad.animation runAction:seq];
} else {
[thisDoodad.animation runAction:moveAction];
}
自提问时起,我尝试添加以下行:
[[animation texture] setAliasTexParameters];
它消除了玩家的模糊精灵,但略微拉伸了图像。 值得一提的是,每个精灵帧都是32x32像素,并没有填满整个帧 另外,上面的代码行不会影响ai的sprite的外观。
* ------- * 编辑::
我修好了。
发生了什么:
我有两个浮点数,用于保存精灵即将移动到屏幕上的位置。 我世界上所有其他精灵都来自玩家的参考。
在我的引用过程中,float被格式化为一个int,因此游戏中的每个其他sprite都会收到该位置的int版本。
这让我相信,在我的代码中某处必须有一些可以将这两个浮点数分开的东西。
感谢@jtbandes提供的“半像素值”提示。我仍然不知道这个位置如何成为一个整数但是整数:(
无论如何,将浮动更改为int会修复所有内容。
谢谢!
答案 0 :(得分:1)
也许精灵的位置与半像素值对齐,例如150.5像素。这可能会导致视觉失真/模糊。