2012-03-22 103 views
0

我試圖用的cocos2d做滾動層垂直滾動CCLayerColor問題

我想是該層開始從上往下滾動,但無論何時進入現場層我做什麼位於(0,0)aka..bottom

我試了幾件事情,但似乎沒有任何工作

-(id) init 
{ 
    if((self=[super init])) { 
     self.isTouchEnabled = YES; 
     isDragging = NO; 
     yvel = 0.0f; 
     contentHeight = 1000.0f; 

     scrollLayer = [CCLayerColor layerWithColor:ccc4(200, 200, 200, 240)]; 
     scrollLayer.contentSize = CGSizeMake(320,contentHeight); 
     scrollLayer.anchorPoint = ccp(0,1); 
     scrollLayer.position = ccp(0, 480); 
     [self addChild: scrollLayer]; 


     CCLabelTTF *label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"test label"] 
                fontName:@"Marker Felt" 
                fontSize:24]; 

     label.position=ccp(100, 100); 

     [scrollLayer addChild:label]; 


     [self scheduleUpdate]; 
    } 
    return self; 
} 

其他方法更新,觸動的處理器,這樣的問題不能be there

與此代碼...不應該它與屏幕左上角的內容初始化?一個痛苦的幾個小時,我終於解決了這個問題後

回答

0

...但我仍然不知道爲什麼它的scrollLayer.position = ccp(0, 480);

相反,我換成scrollLayer.position =ccp(0,-contentHeight);和刪除scrollLayer.anchorPoint = ccp(0,1);的Cuz它不是做什麼

和我絕對不知道爲什麼它的作品

有人可以解釋這一點嗎?