0
votes

I want to set the contentsize of scrollayer.

I have a scrollayer, it's CCLayer type and moving is set by ccTouchMove. I have one schedule for smoothing. BUT.

Problem is that scrolling layer is big like the whole display. I want to set the contentsize of scrollayer. Content in this layer will be scroll and showing ONLY in this layer. Not taking up the whole display. Something like this

enter image description here

Scrolling just in gray CCLayer (scrollayer) ....NOT WHOLE SCREEN.

Can you help me?

P.S.: Setting CCLayerColor and initWithColor:Width:Height: is not working. It just makes some stupid color box and it's moving too.

2
What is the white rectangle ? is it a mask masking part of the scrolling layer that remains in place during the scrolling action , or did you mean that only the cropped part of the scrolling layer would be shown, but the background (behind the scrolling image) would show through where the white rectangle is ?YvesLeBorg
z-index:0 --- background content, for exmaple white CCSprite, z-index:1 --- CCLayer ScrollLayer - INSIDE scrolllayer will be objects for exmaple CCLabelTTF. .......Inside means that CCLabelTTF will be child of CCLayer scrolllayermayoxy
but.. if i thinking of this now,... scrolllayer is moving, scrolling,. so...mayoxy

2 Answers

0
votes

ok, honestly i would put the window frame at a higher z than the scrolling object ... if you dont you may have to crop and change sprite on the fly for the window content, nasty (at least that is the one way i could do this, without further research).

so :

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

This is the basic idea. You may need clamping logic to prevent the creeping of scrollableContent beyond the edges of the window.

Edited for typos.

0
votes

After trying desperately with masking and GL_SCISSOR, I settled on cutting a hole in the foreground and only moving the background object when onTouchMoved updated.

To see it in action, have a look at the Stats page of Angry Gran.