0

我想设置滚动条的内容大小。

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

问题是滚动层像整个显示器一样大。我想设置滚动条的内容大小。此图层中的内容将滚动并仅在此图层中显示。不占用整个显示器。像这样的东西

在此处输入图像描述

仅在灰色 CCLayer (scrolllayer) 中滚动 ....不是整个屏幕。

你能帮助我吗?

PS:设置 CCLayerColor 和 initWithColor:Width:Height: 不起作用。它只是制作了一些愚蠢的彩盒,而且它也在移动。

4

2 回答 2

0

在拼命尝试使用遮罩和 GL_SCISSOR 之后,我决定在前景上切一个洞,并且只在onTouchMoved更新时移动背景对象。

要查看它的实际效果,请查看Angry Gran的 Stats 页面。

于 2012-01-18T16:59:46.577 回答
0

好的,老实说,我会将窗口框架放在比滚动对象更高的 z 位置......如果你不这样做,你可能不得不为窗口内容动态裁剪和更改精灵,讨厌(至少这是我可以的一种方式这样做,无需进一步研究)。

所以 :

// 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
  }
}

这是基本思想。您可能需要钳位逻辑来防止可滚动内容爬出窗口边缘。

编辑错别字。

于 2012-01-18T16:55:00.437 回答