本文整理汇总了C++中EventHandler::setRemoveId方法的典型用法代码示例。如果您正苦于以下问题:C++ EventHandler::setRemoveId方法的具体用法?C++ EventHandler::setRemoveId怎么用?C++ EventHandler::setRemoveId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventHandler
的用法示例。
在下文中一共展示了EventHandler::setRemoveId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void TutorialApp::update()
{
/*
* An event handler is a good place to add functionality
* to your UiTree. Think of it as a many application for
* your node. In this case, we've added some logic to the
* event handler to record the ID of any node that needs
* to be removed.
*/
uint64_t removeId = mEventHandler.getRemoveId();
/*
* When removing a node, be sure to also remove any
* external data it is using to save on resources.
*/
if ( removeId > 0 && mUiTree.removeChild( removeId ) ) {
if ( mIdBatchMap.find( removeId ) != mIdBatchMap.end() ) {
mIdBatchMap.erase( removeId );
}
makeNode();
}
mEventHandler.setRemoveId( 0 );
const float e = (float)getElapsedSeconds();
/*
* If you ever need a flat list of all nodes in your UiTree,
* run a query which returns true.
*/
list<UiTree*> nodes = mUiTree.query( []( const UiTree& node )
{
return true;
} );
const vec2 c = getWindowCenter();
/*
* Although there is an update event in the UiTree, it is
* best to keep the quantity of update signals to a minimum.
* If you want to organize your code a bit, consider writing
* "controller" nodes. That is, create a node's event handler
* with some more sophisticated callbacks. If you have hundreds
* or thousands of nodes that all have update or mouse events,
* for example, you might get better performance by hit testing
* them all from a single node instead of giving them all
* their own event handlers. In this example, we update the tree
* from the main application's update loop.
*/
for ( UiTree* a : nodes ) {
if ( a->getParent() != nullptr ) {
UiData& data = a->getData();
const float s = data.getSpeed();
a->setTranslate( c + vec2( cos( e * s ), sin( e * s ) ) * data.getDistance() );
float d0 = numeric_limits<float>::max();
for ( UiTree* b : nodes ) {
if ( a != b && b->getScale().x > a->getScale().x ) {
const float d1 = glm::distance( a->getTranslate(), b->getTranslate() );
if ( d1 < d0 ) {
d0 = d1;
a->setParent( b );
}
}
}
}
}
}