Hi Andreas,
The only way to fix the CCMenu issue is to make a CCMenu subclass and implement this function:
//MenuPanel is a CCMenu subclass
void MenuPanel::registerWithTouchDispatcher()
{
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
Here’s the MenuPanel subclass I’m using:
MenuPanel.h
#include "cocos2d.h"
USING_NS_CC;
class MenuPanel : public CCMenu
{
public:
MenuPanel(){}
virtual ~MenuPanel(){}
static MenuPanel* create(CCMenuItem* item, ...);
virtual void registerWithTouchDispatcher();
};
MenuPanel.cpp
#include "MenuPanel.h"
MenuPanel* MenuPanel::create(CCMenuItem* item, ...)
{
va_list args;
va_start(args, item);
MenuPanel *pRet = new MenuPanel();
if (pRet && pRet->initWithItems(item,args))
{
pRet->autorelease();
va_end(args);
return pRet;
}
va_end(args);
CC_SAFE_DELETE(pRet);
return NULL;
}
void MenuPanel::registerWithTouchDispatcher()
{
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
I attach you my last implementation of CCSlidingLayer, since I found more bugs. (Can’t do it perfect at first time ;))
You have to take care about a couple of things:
1 - When you create a CCMenu or a subclass of it, and you want to add it to CCSlidingLayer, you have to set the CCMenu size to what it’s containing size.
I mean, when you create a menu, at least it happens when I create them, its size is equal to window size (320x480 on win32). And that’s not what we want. You have to myMenu~~>setContentSize) and then add it to CCSlidingLayer.
Also you are adding CCMenuItemSprite’s which I’m not sure if that’s fine for CCLayers.
Try this code, it should work BUT USING A CCMENU SUBCLASS.
<pre>
header = CCSprite::create;
game1 = CCSprite::create;
game2 = CCSprite::create;
footer = CCSprite::create;
////////////////
//MENU SETTINGS
float menuHeight = 0.0f;
CCMenuItemSprite menuHeader = CCMenuItemSprite::create);
CCMenuItemSpritemenuGame1 = CCMenuItemSprite::create);
CCMenuItemSprite menuGame2 = CCMenuItemSprite::create);
CCMenuItemSpritemenuFooter = CCMenuItemSprite::create);
CCMenu* menu = MenuPanel::create;
menuHeight = menuHeader~~>getContentSize().height
- menuGame1~~>getContentSize.height
- menuGame2~~>getContentSize().height
- menuFooter~~>getContentSize.height;
menu~~>setContentSize(CCSize(winSize.width, menuHeight));
/////////////////
//Sliding layer
CCSlidingLayer* slidingLayer = CCSlidingLayer::create( Vertically, CCSizeMake(winSize.width, winSize.height), CCRectMake(0,0,winSize.width,winSize.height), ccc4(0,0,0,0));
// To let the slidingLayer resize itself, use a lower height:
// CCSlidingLayer* slidingLayer = CCSlidingLayer::create( Vertically, CCSizeMake(winSize.width, 1), CCRectMake(0,0,winSize.width,winSize.height), ccc4(0,0,0,0))
slidingLayer~~>addChildWithSize, kAlignmentCenter);
this~~>addChild( slidingLayer );
Also don’t forget you can put some color in the SlidingLayer to see if it’s working properly.
Hope this helps.
PS: CCSlidingLayer doesn’t handle quite well when you add a CCLayer to it and then resize that CCLayer. The workaround is to add directly the items in the
CCSlidingLayer