Skip to content

Instantly share code, notes, and snippets.

@kyokomi
Created May 3, 2014 11:36
Show Gist options
  • Save kyokomi/1c66076f1fe542965486 to your computer and use it in GitHub Desktop.
Save kyokomi/1c66076f1fe542965486 to your computer and use it in GitHub Desktop.
Cocos2d-xのMenu内のMenuItemをタッチしたときMenu内の他MenuItemをデフォルト色にして選択したMenuItemだけ別の色に変える
//
// MenuItemUtil.h
//
// Created by kyokomi on 2014/05/03.
//
//
#ifndef Kyokomi_MenuItemUtil_h
#define Kyokomi_MenuItemUtil_h
#include "cocos2d.h"
class MenuItemUtil
{
public:
static void touchItemRefreshColor(cocos2d::Ref *ref,
const cocos2d::Color3B touchColor,
const cocos2d::Color3B untouchColor = cocos2d::Color3B::WHITE) {
auto menuItem = dynamic_cast<cocos2d::MenuItem*>(ref);
if (menuItem->getParent()->getChildrenCount() < 1) {
return;
}
// Menuにぶら下がってるMenuItemの色を全部戻してタッチしたやつだけ色つける
for (auto node : menuItem->getParent()->getChildren()) {
node->setColor(untouchColor);
}
menuItem->setColor(touchColor);
}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment