Cocos2d iphone cocos2diphone。滚动层内容大小。层

Cocos2d iphone cocos2diphone。滚动层内容大小。层,cocos2d-iphone,cclayer,Cocos2d Iphone,Cclayer,我想设置scrollayer的contentsize 我有一个scrollayer,它是CCLayer类型,移动由ccTouchMove设置。我有一个平滑的时间表。但是 问题是滚动层和整个显示器一样大。我想设置scrollayer的contentsize。此层中的内容将滚动并仅显示在此层中。没有占据整个画面。像这样的 仅在灰色CCLayer(scrollayer)中滚动…而不是整个屏幕 你能帮我吗 注意:设置CCLayerColor和initWithColor:Width:Height:无效。

我想设置scrollayer的contentsize

我有一个scrollayer,它是CCLayer类型,移动由ccTouchMove设置。我有一个平滑的时间表。但是

问题是滚动层和整个显示器一样大。我想设置scrollayer的contentsize。此层中的内容将滚动并仅显示在此层中。没有占据整个画面。像这样的

仅在灰色CCLayer(scrollayer)中滚动…而不是整个屏幕

你能帮我吗


注意:设置CCLayerColor和initWithColor:Width:Height:无效。它只是制造了一些愚蠢的颜色框,而且它也在移动。

好吧,老实说,我会把窗口框放在比滚动对象更高的z位置。。。如果你不这样做,你可能不得不在运行中裁剪和更改窗口内容的sprite,这很糟糕(至少这是我可以做到的一种方法,无需进一步研究)

因此:

这是基本思想。您可能需要钳制逻辑来防止可滚动内容从窗口边缘向外爬行


为拼写错误而编辑。

在拼命尝试掩蔽和GL_剪刀后,我决定在前景上切一个洞,只有在
onTouchMoved
更新时才移动背景对象


要查看它的实际应用,请查看的统计信息页面

白色的长方形是什么?是滚动层的遮罩部分在滚动过程中保持不变,还是说仅显示滚动层的裁剪部分,但背景(滚动图像后面)将显示白色矩形的位置?z-index:0---背景内容,对于exmaple white CCSprite,z索引:1---CCLayer SCROLLAYER-CROLLAYER内部将是exmaple CCLabelTTF的对象。。。。。。。Inside表示CCLabelTTF将是CCLayer scrolllayerbut的子级。。如果我现在想到这一点,。。。滚动层正在移动,滚动,。所以
// initialize this logic somewhere useful

CCNode scrollableContent;
CCSprite windowFrame; 
BOOL isScrollPossible;
[self addChild:scrollableContent z:0];
[self addChild:windowFrame z:1];

// and in the touch delegate methods

-(void) ccTouchBegan:{
  check if the touch happened in the window, if yes, scrolling is possible
}
-(void) ccTouchMoved:{
  if (isScrollPossible) {

    compute displacement
    compute nextPosition for scrollableContent node;
    if ( nextPosition in window ) {
      // make scrollableContent follow touch
      scrollableContent.position=nextPosition;
    } else {
      // stop any further scrolling until the next 'touch began'
      isScrollPossible=NO; 
    }
  } else {
    // scroll not possible, do nothing
  }
}