xcode - Cocos2d how to scale a sprite without scaling layer? Or, How to scale and crop sprite/layer? -


ipad app setup: scenea contains layera - 1024x768. push button in layera, layerb drops down on top using ccmoveto action. layerb 800x600 can see layera behind (think of overlayed pause screen type effect). layerb contains 800x600 sprite user can zoom in on pressing button. zoom effect combination of ccscaleto , ccmoveto keep centered on part it's zooming in on. however, when sprite scales, layerb overtop of layera. there way scale sprite within contained window?

layerb should use gl_scissor_test trim outside of itself. can google more information it, defines rect , uses glscissoron remove outside. have class extend when need this, goes follows:

// //  ccnodeclip.h // //  created ignacio orlandoni on 7/29/11. //  #import <foundation/foundation.h> #import "cocos2d.h" @interface ccnodeclip : cclayer {  }  -(void)previsit; -(void)postvisit;  @end 

-

// //  ccnodeclip.m // //  created ignacio orlandoni on 7/29/11. //  #import "ccnodeclip.h" @implementation ccnodeclip  -(void)visit {     [self previsit];     [super visit];     [self postvisit]; }  -(void)previsit {     if (!self.visible)         return;      glenable(gl_scissor_test);      cgpoint position = [self position];      //i don't remember if rect serves both orientations, may need change order of values here.     cgrect scissorrect = cgrectmake(position.x, position.y, [self contentsize].width, [self contentsize].height);      //    cclog(@"scrissor rect: x: %02f, y:%02f, w: %02f, h: %02f", scissorrect.origin.x,     scissorrect.origin.y, scissorrect.size.width, scissorrect.size.height);      // handle retina     scissorrect = cc_rect_points_to_pixels(scissorrect);      glscissor((glint) scissorrect.origin.x, (glint) scissorrect.origin.y,               (glint) scissorrect.size.width, (glint) scissorrect.size.height); }  -(void)postvisit {     gldisable(gl_scissor_test); }   @end  

with imported layerb, can define ccnodeclip instead of cclayer.

some links...

glscissor << cocos2d forum

circle shape clipping opengl-es in cocos2d << stackoverflow

cocos2d iphone - sprite cliping/mask/frame << stackoverflow

another cocos2d gem: clippingnode << learn-cocos2d.com

as side note...

ccscaleto + ccmoveto can avoided if anchor point sprite centered, image stays centered in container scales. (.anchorpoint = ccp(0.5, 0.5);)


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -