0
votes

Let me start by explaining what I am trying to do. I have a full screen animation with about 73 frames and with these images being so large I am not able to use sprite sheets so I am just adding them to an animation as seperate spriteframes. My goal is to have the animation play through and then have it disappear from left to right. The way that I am achieving this look is by updating the width of the (textureRect) of the frames and eventually making the textureRect width 0. So I have set up the CCSprite that I am going to run the animation on.

-(id) init {

    if( (self=[super init])) {

        self.transSprite = [CCSprite spriteWithFile:@"transition0.pvr.ccz"];

        if (CC_CONTENT_SCALE_FACTOR() == 1) {

            //iPhone 3Gs

            self.transSprite.scaleX = .563;
            self.transSprite.scaleY = .665;

            self.transSprite.position = ccp(self.transSprite.contentSize.height - 3, -1);
            self.transSprite.anchorPoint = ccp(1, 0);
            [self addChild:self.transSprite z:5];

        }

        else if (kiPhone5) {

            //iPhone 5

            self.transSprite.scale = self.transSprite.scale * 1.335f;

            self.transSprite.position = ccp(569, -1);
            self.transSprite.anchorPoint = ccp(1, 0);
            [self addChild:self.transSprite z:5];

        }

        else {

            //iPhone 4

            self.transSprite.scaleX = 1.126;
            self.transSprite.scaleY = 1.33;

            self.transSprite.position = ccp(481, -1);
            self.transSprite.anchorPoint = ccp(1, 0);
            [self addChild:self.transSprite z:5];

        }

    }

    return self;
}

So the reason for checking what device is running, is because I did not make 2 versions of the animation frames HD and SD. Instead I just made them a good in between size and then I check to see what device is running and scale the sprite accordingly. So here is my problem I am setting the Sprites anchorPoint to the bottom right hand corner of the screen so that when I change the width of the textureRect it will decrease in size from left to right. Everything seems to be working great with this idea except for when I change the width of the textureRect of each sprite frame.

- (void) rectUpdate3Gs {

    for (CCAnimationFrame *frame in transition.frames) {
        frame.spriteFrame.rect = CGRectMake(0, 0, 856, 484);
    }

}

- (void) retinaRectUpdate {

    for (CCAnimationFrame *frame in transition.frames) {
        frame.spriteFrame. rect = CGRectMake(0, 0, 428, 242);

    }

}

So when I run the animation and start to change the width of the textureRect it decreases from both the left and the right side, it is like the anchorPoint is being ignored. Do the spriteFrames have there own anchorPoint or what is happening.

Here is an illustration of what is happening.This is the CCSprite set up for the full texture and with the anchorPoint in the bottom right corner. enter image description here

   self.transSprite.scaleX = .563;
    self.transSprite.scaleY = .665;

    self.transSprite.position = ccp(self.transSprite.contentSize.height - 3, -1);
    [self addChild:self.transSprite z:5];
    [self.transSprite setTextureRect:CGRectMake(0, 0, 856, 484)];
    self.transSprite.anchorPoint = ccp(1, 0);

Now this is setting the textureRect of the CCSprite a little smaller.

enter image description here

This is the way that I want it to work, is to subtract the width of the texture from the left to right. But when I change the width of the animation frames to match this subtracted width this is what I get.

enter image description here

I am at a loss as to why this is happening. Do the animation frames not respect the anchor point of the CCSprite they are running on?

1
"I just made them a good in between size" <-- meaning you're wasting memory and performance on SD devices, and make things look blurry on Retina devices and risk disapproval by Apple (Retina assets are now mandatory for Retina devices!). Please reconsider this approach. Regardless, to better understand the issue screenshots would be very helpful.LearnCocos2D
Is there somewhere on the web that you could point me to that shows that apple requires HD graphics on retina devices?Stephen
Here, new guidelines since May 1st 2013: macobserver.com/tmo/article/… You can find the exact wording in the developer center somewhere, I don't know where though. In how far "Retina support" means "all images need to be in full Retina resolution" is up to Apple. Personally I wouldn't risk not using full Retina resolution, at least not for the foreground visuals.LearnCocos2D

1 Answers

0
votes

Scaling issue aside, there's 2 things you can do. First, and probably easiest, is to simply add a CCLayerColor on top of the animation and scale that down accordingly. This way you don't need to modify every animation frame's rect.

Second option would be to use a clipping node, found here:

Here