cocos2d iphone - CCSprite anchorPoint not working as expected? -


let me start explaining trying do. have full screen animation 73 frames , these images being large not able use sprite sheets adding them animation seperate spriteframes. goal have animation play through , have disappear left right. way achieving updating width of (texturerect) of frames , making texturerect width 0. have set ccsprite going run 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 reason checking device running, because did not make 2 versions of animation frames hd , sd. instead made them in between size , check see device running , scale sprite accordingly. here problem setting sprites anchorpoint bottom right hand corner of screen when change width of texturerect decrease in size left right. seems working great idea except when change width of texturerect of each sprite frame.

- (void) rectupdate3gs {      (ccanimationframe *frame in transition.frames) {         frame.spriteframe.rect = cgrectmake(0, 0, 856, 484);     }  }  - (void) retinarectupdate {      (ccanimationframe *frame in transition.frames) {         frame.spriteframe. rect = cgrectmake(0, 0, 428, 242);      }  } 

so when run animation , start change width of texturerect decreases both left , right side, anchorpoint being ignored. spriteframes have there own anchorpoint or happening.

here illustration of happening.this ccsprite set full texture , anchorpoint in 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 setting texturerect of ccsprite little smaller.

enter image description here

this way want work, subtract width of texture left right. when change width of animation frames match subtracted width get.

enter image description here

i @ loss why happening. animation frames not respect anchor point of ccsprite running on?

scaling issue aside, there's 2 things can do. first, , easiest, add cclayercolor on top of animation , scale down accordingly. way don't need modify every animation frame's rect.

second option use clipping node, found here:

here


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -