2012-01-17 67 views
0

我想设置scrollayer的内容。Cocos2d iPhone。 Scrollayer contentSize。图层

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

问题在于滚动层像整个显示器一样大。我想设置scrollayer的内容。此图层中的内容将滚动并仅显示在此图层中。没有占用整个显示器。事情是这样的

enter image description here

滚动只是在灰色CCLayer(scrollayer)......而不是整个屏幕。

你能帮我吗?

P.S .:设置CCLayerColor和initWithColor:宽度:高度:不起作用。它只是使一些愚蠢的彩盒,它也在移动。

+0

什么是白色矩形?它是在滚动动作期间保持原位的滚动图层的掩模部分,还是您的意思是只显示滚动图层的裁剪部分,但背景(滚动图像后面)将显示白色矩形是? – YvesLeBorg 2012-01-17 23:00:16

+0

z-index:0 ---背景内容,例如白色的CCSprite,z-index:1 --- CCLayer ScrollLayer - INSIDE scrolllayer将是例如CCLabelTTF的对象。 .......里面意味着CCLabelTTF将是CCLayer的滚动层 – mayoxy 2012-01-18 10:53:47

+0

的孩子,但..如果我现在想这个,... scrolllayer正在移动,滚动,。所以... – mayoxy 2012-01-18 10:56:47

回答

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

这是基本的想法。您可能需要夹紧逻辑来防止滚动内容超出窗口边缘。

为错别字编辑。

0

拼命地尝试屏蔽和GL_SCISSOR之后,我决定在前景中切割一个洞,并在更新onTouchMoved时只移动背景对象。

要看到它的行动,看看Angry Gran统计页面。