Question

A picture is worth a thousand words. Here's mine:

Messed up sprite next to good sprite

Above depicts two sprites, the one on the centre right is the player, and the one on the centre left is an AI player. Both of their initializations use the same superClass. We should see similar quality sprites.

However, as you can see, the right sprite is somehow distorted. I also noticed flecks of other sprites from the same spriteSheet appearing above and below on some animation frames. No transformations are ever done on the player sprite. No actions other than those also performed on the ai sprites are ever run.

Has anyone else encountered this? I'm not even sure how to phrase this problem ;) Any more questions? Please ask!

Details: I'm using Cocos2d 1.0.0.. Xcode 4.1 running on Lion.

Code Samples: This code is run after the initialization of an NSObject containing CCFiniteTimeActions, and a 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];

the variable "sprites" is a pointer to a CCSpriteBatchNode. I am certain they point to the same batch node, as there is only one.

As you can see, this object adds its own animation to the layer via batch node.

I'll post the method where the movement occurs:

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];
    }

Since the time of asking, I have tried adding the line:

[[animation texture] setAliasTexParameters];

It rid the player's sprite of the blur, but stretched the image slightly wide. It's probably worth mentioning that each of these sprite frames are 32x32 pix, and do not fill the entire frame.
Additionally, the above line of code did not affect the appearance of the ai's sprites.

* ------- * Edit::

I fixed it.

What happened:

I have two floats which hold the location the sprite is about to move to on screen. All other sprites in my world are drawn from the player's reference.

During my referencing, the float was formatted into an int, so every other sprite in the game received the int version of the position.

This leads me to believe, somewhere in my code there must be something that fractionalizes these two floats.

Thanks @jtbandes for the "half pixel value" hint. I still do not know how the position became anything but an integer though :(

Anyways, changing the floats to ints fixed everything.

Thanks!

Was it helpful?

Solution

Perhaps the position of the sprite is aligned to a half-pixel value, such as 150.5 pixels. This could cause the visual distortion/blurring.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top