cocos2d-x tree 控件实现

前端之家收集整理的这篇文章主要介绍了cocos2d-x tree 控件实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

闲来无聊码码代码 哈哈

使用的是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(); }

猜你在找的Cocos2d-x相关文章