2012-01-09 88 views
0

我主要功能那里我画背景:绘制图像在cocos2d

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

     CGSize size = [[CCDirector sharedDirector] winSize]; 

     CCSprite * background = [CCSprite spriteWithFile:@"backg.png"]; 

     background.anchorPoint = ccp(1, 1); 

     background.position = ccp(size.width, size.height); 
     [self addChild:background z:-1]; 

     self.isTouchEnabled = YES; 
    } 
    return self; 
} 

和功能在那里我得到触摸,然后对程序逻辑。但我不知道我怎么能从她身上吸引。

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 


    int a[3][3],fail,hod,i,k,win,x,y; 

    for(i=1; i<=3; i++) 
    { 
     for(k=1; k<=3; k++) 
     { 
      a[i][k]=0; 
     } 
    } 

    win=0; 
    hod=1; 

    while(win==0) 
    { 
     if(hod%2==1) 
     { 
      UITouch *touch = [touches anyObject]; 
      CGPoint location = [touch locationInView:[touch view]]; 
      location = [[CCDirector sharedDirector] convertToGL:location]; 
      x=location.x; 
      y=location.y; 
      NSLog(@"%d %d",x,y); 
      //here i should draw 
      hod++; 
     } 
    } 
} 

如何,我可以从第二个功能上攻背景,发生在第一功能绘制一个形象呢?

回答

0

在Cocos2D中,你不会画东西。您添加或删除节点(精灵,标签等)。你可以重新定位它们。您可以重新排序它们的z顺序以更改哪个节点位于其他节点的前面。但是绘图是由Cocos2D内部完成的。

当然也有一些例外情况,但自定义绘图仅限于 - (void)绘制方法,并且有些东西告诉我您实际上并不想使用OpenGL开始绘制东西。