Scrolling vertically a CCMenu

Attached MenuPanel working for version cocos2d-2.1beta3-x-2.1.1

Thank you danadn*.
Very nice.
ScrollView is, indeed, quite difficult to grasp.
For these tasks, I’m living with something similar to the first thing you posted here; a scrollable CCLayer, CCMenu and some kind of “touchsMoving” flag.
With some basic easing actions , I don’t really see the need of using a more sophisticated solution.
Overriding MenuItem draw method, you can even get easily an alpha clipping effect.
Maybe I’m missing something. Danadn* what are you really getting from implementing your own MenuPanel?

I implemented my own MenuPanel because when I use a CCMenu I can’t move the CCSlidingLayer if I touch inside the CCMenu. I’m sure than with a menu->setWhatever(false/true) I wouldn’t need to implement my own CCMenu but I tried a few setters and none seemed to work fine.

The reason that made me leave my CCActions implementation was that this one is based more on physics than just calculating how long should the CCMove action move and looks smoother (at least smoother than my first implementation). Right now CCSlidingLayer doesn’t have the “you passed the end-of-the-list” effect, but once I finish my app I’ll start taking care of that kind of things. This implementation is based on the update function and most sure the performance is the same than applying a CCAction, at least it runs fast on devices.

Do you mean with alpha clipping that clipping that appears on android menus? That sounds pretty interesting for example for a Settings Menu, mind you post some code showing how to do that?

Sorry for the delay.
What I was talking about is something quite simple.

The key idea is calculating the alpha os every item prior drawing, based on some clipping settings (size and alpha range or decay rate, basically)

void MenuPanel::clip( CCRect iRange, bool iHorizontal )
{
   CCObject *obj;
   CCNode *node;
   CCRGBAProtocol *rgbObj;
   CCArray* items = getChildren();

   // [TODO] To make this shorter, and for the shake of clarity,
   // I'll only show the vertical clipping
   if (iHorizontal)
      return;

   // vertical alpha clipping
   CCARRAY_FOREACH( items, obj )
   {
      node = dynamic_cast(obj);
      if (node != NULL)
      {
         float posY = node->getPositionY() + m_obPosition.y;
         int alfa = 255;
         if ( posY > iRange.getMaxY() )
         {
            float tmp = ( (posY - iRange.getMaxY() ) / _decayLength);
            alfa = 255 - 255 * tmp;
         }
         if ( posY < iRange.getMinY() )
         {
            alfa = 255 - 255 * ( ( iRange.getMinY() - posY ) / _decayLength);
         }

         if (alfa < 0)
            alfa = 0;

         if (alfa > 255)
            alfa = 255;

         rgbObj = dynamic_cast(obj);
         if (rgbObj != NULL)
         {
            rgbObj->setOpacity( (GLubyte)alfa );
         }
      }
   }
}

And then override the visit method:

void MenuPanel::visit()
{
   if (_isClipping)
      clip( _clipRange, _isHorizontalClip );
   CCMenu::visit();
}

Also, my setting for touch management are illustrated by the following code:
(using targeted delegate NOT swallowing touches, thus the override and checking if some touch is outside the active area, in which case the touch is discarded)

void MenuPanel::registerWithTouchDispatcher()
{
    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->addTargetedDelegate(this, this->getTouchPriority(), false);
}


bool MenuPanel::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
   if (_activeRange.containsPoint( touch->getLocation() ) )
      return CCMenu::ccTouchBegan( touch, event );

   return false;
}

My implementation on top of CCMenu is below 200 lines of code.
Hope it helps.

Hi Ardhan S,

Can you share an example project please?

Some idea for a roulette effect?

Hope you can,

Thanks

Please help i m stuck in ccmenu & ccscrollview how should i use them and ccmenu are clickable out side the ccscrollview invisible size