엘프 가시 구역(TextureRect)과 닻점(anchorPoint)을 유연하게 사용하고 가시 구역과 닻을 결합하여 진도표를 제작합니다!

4188 단어 플레이cocos2d

                 ;
                 :      ;
                                 ,  Kjava(J2me)   setClip  ,Android clipRect    ,   iOS      ,      cocos2d            setTextureRect;
                        ,  Himi      :
                                  ,            ,           ;                  ,            ;
               , cocos2d   CCSprite                  :
1.            ;2.        ;    :
            cocos2d  ,   HelloWorldLayer.m init         ,    :
[cpp] view plaincopy
//---     icon   
CCSprite * spriteOld =[CCSprite spriteWithFile:@"icon.png"];  
spriteOld.position=ccp(80,100);  
[self addChild:spriteOld];  
//---     30 30        
CCSprite * spriteNew =[CCSprite spriteWithFile:@"icon.png" rect:CGRectMake(0, 0, 30,30)];  
spriteNew.position=ccp(150,100);  
[self addChild:spriteNew];  
//---       30 30        
CCSprite * spriteT =[CCSprite spriteWithFile:@"icon.png"];  
[spriteT setTextureRect:CGRectMake(10, 10, 30, 30)];  
spriteT.position=ccp(230,100);  
[self addChild:spriteT];   

           3   ,            icon  ,                30 30   ,                    ,       ;                    ,                 ,        ,      ;
                                     CGRect  ,  CGrect     ,  x,y,    w,y;
      CGRect              :
    CGRect x,y          (x,y)          ,(w,h)       ;    
             ,         (    )            :
 					

     	          :    (anchorPoint);
                                 ,            :
           、     、     、     、       
                 , cocos2d    layer                      ;
          cocos2d layer   (0,0)        ,               layer   ,          layer    ,                      ,   :
    			     
                      :
[cpp] view plaincopy
//---        
CCSprite * spriteOld =[CCSprite spriteWithFile:@"icon.png"];   
[self addChild:spriteOld];  

                              icon      ,           layer     ,   :
    			    
                :
[cpp] view plaincopy
//---            
CCSprite * spriteNew =[CCSprite spriteWithFile:@"icon.png"];  
spriteNew.anchorPoint=ccp(0,0);  
[self addChild:spriteNew];  

                  anchorPoint  ,     CGPoint  , CGPoint  x y   1,       ;
    
      ---------         ,    Himi                           ;
              cocos2d icon        ,              ;    :
       :      ,        x=0(   ),y=0.5(   y   ),    :
[cpp] view plaincopy
//---        
CCSprite * spriteP =[CCSprite spriteWithFile:@"icon.png"];    
spriteP.position=ccp(size.width*0.5,size.height*0.5);//      
spriteP.anchorPoint=ccp(0,0.5);//      
[self addChild:spriteP z:0 tag:88]; //      layer     
                                          , ,            ,                ;
      :              :
[cpp] view plaincopy
@interface HelloWorldLayer : CCLayer  
{  
    float currentShowRect;//           
}  
             :
  
[cpp] view plaincopy
-(id) init  
{  
    [self scheduleUpdate];  
}  
-(void)update:(ccTime)himi{//            
  
}  
   
       :                icon       ,    :
[cpp] view plaincopy
-(void)update:(ccTime)himi{//            
    //         
    CCSprite *sprite =(CCSprite*)[self getChildByTag:88];  
    currentShowRect++;  
    if(currentShowRect>=100){  
        currentShowRect=0;  
    }  
    [sprite setTextureRect:CGRectMake(0, 0, currentShowRect,sprite.position.y)];  
      
}  

          :(icon        ,    )
				

       OK,      ,                 ,         Himi     ,      Himi                      ,   ,         ,        ,       。   ,Himi   ,      ,        ,                      ;

[검은 쌀 Game Dev 블록]에서 원본 링크로 옮겨 싣기:http://www.himigame.com/iphone-cocos2d/501.html

좋은 웹페이지 즐겨찾기