CCScrollView with CCMenu,How to control the touch area!??

I have CCScrollView with CCMenus,when the menu scroll out of the visible area,It’s also can be touched too.How can I control the area???

I’m on the same boat, could you solve it?

Josejulio Martínez Magaña wrote:

I’m on the same boat, could you solve it?

If u know chinese,u can see this:
http://blog.csdn.net/jlstmac3/article/details/8091799
if not ,see this:
http://yui.co/make-ccscrollview-work-with-ccmenuitemimage/

Thank you, i did solved it different, if anyone wants further info i’ll glad post snippets

Josejulio Martínez Magaña wrote:

Thank you, i did solved it different, if anyone wants further info i’ll glad post snippets

Could you show your solution ? I have similar problem with CCControlButtons.

If you will still be interested on Wednesday I can also post code snippets, as I don’t have access to the code right now :slight_smile:

If you don’t have access to the code could you describe the idea of solution ?

Well, you add a ScrollView, and then some things to it :smiley:
The thing is that I wrote this module a few months back, and simply don’t remember how :smiley:
Anyway I’ll post it tomorrow as soon as I reach my work computer :slight_smile:

So, after checking my code, It seems that my solution is the one provided by jlstmac2 jiang here : http://yui.co/make-ccscrollview-work-with-ccmenuitemimage/ with really minor changes.
So the thing is that you have to subclass the CCScrollView and register it with the TouchDispatcher with the lowest possible value ( INT_MIN + 1 for example). The way cocos interprets this values is, that an object with lowest value gets the touch first, so essentially you just need to set this value to be lower than that of CCMenu (–128, as far as I remember).
Than, according to what you want to achieve you need to implement the Touch methods (touchBegan/Moved/Ended) so that if conditions are met to “click” a button in the menu, you pass the touch to the menu and it handles it so that the correct button is clicked. Otherwise you pass the call to base class (so to CCScrollView) which handles the scrolling :slight_smile:

Let me know if anything is unclear in my explanation or in the code in the linked tutorial and I will try to help :slight_smile:

I didn’t understand your solution but you got me a new idea :slight_smile: Thanks !

My problems:
There is a scrollView with many buttons (items). Above it there are 2 function buttons (return, start).

  1. When I scroll down item buttons overlie function buttons. When I swallow all touches above my scrollview I will lose my function buttons. So I have to find another solution.

  2. When I start draging scroll view a item button is pressed. When I ended the button action will be execute. This is very annoying.

But there is the solution. I have created new CCControlButton. It checks whether was clicked outside scrollview or was dragged. The button is used for items buttons.

bool ControlButtonForScrolling::checkIfTouchIsInsideScrollView(CCTouch *pTouch)
{
    CCPoint touchLocation = pTouch->getLocation(); // Get the touch position
    touchLocation = _scrollView->getParent()->convertToNodeSpace(touchLocation);
    CCRect bBox=_scrollView->boundingBox();
    bool result = bBox.containsPoint(touchLocation);
    return result;
}

bool ControlButtonForScrolling::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
    bool isInside = this->checkIfTouchIsInsideScrollView(pTouch);
    if (isInside) {
        return CCControlButton::ccTouchBegan(pTouch, pEvent);
    }
    else
    {
        return false;
    }
}

void ControlButtonForScrolling::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
    CCControlButton::ccTouchMoved(pTouch, pEvent);
    _scrollWasDragged = true; // information about dragging is stored to prevent sending action
}

void ControlButtonForScrolling::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
    // this method is a copy of CCControlButton::ccTouchEnded except lines with _scrollWasDragged
    m_eState = CCControlStateNormal;
    m_isPushed = false;
    setHighlighted(false);

    if (!_scrollWasDragged)
    {
        if (isTouchInside(pTouch))
        {
            sendActionsForControlEvents(CCControlEventTouchUpInside);
        }
        else
        {
            sendActionsForControlEvents(CCControlEventTouchUpOutside);
        }
    }
    _scrollWasDragged = false;
}

Sorry for the lateness of my answer, i see that you already solved your problem, but here is what worked for me:

I have a main layer (CCLayer) that contains a CCScrollView, which in turn contains many of the CCMenu, what I did is the following:

Disabled the touch for the CCScrollView and for every CCMenu: setTouchEnabled(false)
Enabled the touch for the main Layer: setTouchEnabled(true);
Added every CCMenu to a CCArray and created a CCArray (*menus) for the menus that have been touched
In the main layer i overwrite the methods for the touch handling as follows:

<pre>
bool MainLayer::ccTouchBegan {
if ) {
CCObject* obj;
CCARRAY_FOREACH {
if~~>ccTouchBegan) {
this~~>menuBegan~~>addObject;
}
}
}
return true;
}
void MainLayer::ccTouchMoved {
scroll~~>ccTouchMoved(pTouch, pEvent);
CCObject* obj;
CCARRAY_FOREACH(this~~>menuBegan, obj) {
static_cast<CCMenu
>>ccTouchMoved;
}
}
void MainLayer::ccTouchEnded {
scroll
>ccTouchEnded;
CCObject* obj;
CCARRAY_FOREACH {
static_cast<CCMenu
>>ccTouchEnded;
}
this
>*menuBegan~~>removeAllObjects();
}

void MainLayer::ccTouchCancelled(CCTouch pTouch, CCEventpEvent) {
scroll~~>ccTouchCancelled;
CCObject* obj;
CCARRAY_FOREACH {
static_cast<CCMenu*>>ccTouchCancelled;
}
this
>_menuBegan~~>removeAllObjects();
}

To everyone,if u want to create a ccscrollview with buttons.cctabelview maybe more comfortable
Josejulio Martínez Magaña wrote:

Sorry for the lateness of my answer, i see that you already solved your problem, but here is what worked for me:
>
I have a main layer (CCLayer) that contains a CCScrollView, which in turn contains many of the CCMenu, what I did is the following:
>
Disabled the touch for the CCScrollView and for every CCMenu: setTouchEnabled(false)
Enabled the touch for the main Layer: setTouchEnabled(true);
Added every CCMenu to a CCArray and created a CCArray (_menus) for the menus that have been touched (_menuBegan)
>
In the main layer i overwrite the methods for the touch handling as follows:
>
>
[…]

To everyone,if u want to create a ccscrollview with buttons.cctabelview maybe more comfortable
Josejulio Martínez Magaña wrote:

Sorry for the lateness of my answer, i see that you already solved your problem, but here is what worked for me:
>
I have a main layer (CCLayer) that contains a CCScrollView, which in turn contains many of the CCMenu, what I did is the following:
>
Disabled the touch for the CCScrollView and for every CCMenu: setTouchEnabled(false)
Enabled the touch for the main Layer: setTouchEnabled(true);
Added every CCMenu to a CCArray and created a CCArray (_menus) for the menus that have been touched (_menuBegan)
>
In the main layer i overwrite the methods for the touch handling as follows:
>
>
[…]