闲来无聊码码代码 哈哈
使用的是cocos2d-x 3.12
支持无限层,滚动条,可以直接用,可以直接用了,代码在细节上还可以调整调整
上传时TreeNode 头文件有几个没用到的函数,漏删除了,可以自己删除掉
使用如下:
//1
Tree* _tree = Tree::create();
_tree->setPosition(Vec2(100,100));
this->addChild(_tree);
_tree->setContentSize(Size(150,100));
_tree->createRoot("root",120,22,true);
_tree->addFirstLayerNode("A",22);
_tree->addFirstLayerNode("B",22);
_tree->addFirstLayerNode("C",22);
_tree->addSecondLayerNode(0,"AA",22);
_tree->addSecondLayerNode(1,"BA",22);
_tree->addSecondLayerNode(1,"BB",22);
_tree->addSecondLayerNode(2,"CA",22);
_tree->addSecondLayerNode(2,"CB","CC",22);
//2
cocos2d::EventListenerCustom* _listener = EventListenerCustom::create("TreeSelected",CC_CALLBACK_1(HelloWorld::selectedHandler,this));
_tree->getRootNode()->getEventDispatcher()->addEventListenerWithFixedPriority(_listener,1);
//3
void HelloWorld::selectedHandler(EventCustom* e) { static_cast<TreeNode*>(e->getUserData())->getValue(); }
原文链接:https://www.f2er.com/cocos2dx/339118.html