标签:
动作类Action是一切动作的祖先类。它有三个直接继承子类:
而FiniteTimeAction又有两个直接子类:分别是ActionInstant和ActionInterval,顾类名而思意。
瞬时动作即立即执行动作,下边是其使用示例:
void MyAction::goMenu(cocos2d::Ref *pSender) { log("Tag = %i", this->getTag()); Size size = Director::getInstance()->getVisibleSize(); Vec2 p = Vec2(CCRANDOM_0_1()*size.width, CCRANDOM_0_1()*size.height); switch (this->getTag()) { case PLACE_TAG: sprite->runAction(Place::create(p));// Places the node in a certain position break; case FLIPX_TAG: sprite->runAction(FlipX::create(true));// Flips the sprite horizontally break; case FLIPY_TAG: sprite->runAction(FlipY::create(true));// Flips the sprite vertically break; case HIDE_SHOW_TAG: if (hiddenFlag) { sprite->runAction(Hide::create());// Hide the node hiddenFlag = false; } else { sprite->runAction(Show::create());// Show the node hiddenFlag = true; } break; case TOGGLE_TAG: sprite->runAction(ToggleVisibility::create());// Toggles the visibility of a node break; default: break; } } void MyAction::backMenu(cocos2d::Ref *pSender) { auto sc = HelloWorld::createScene(); // Slide in the incoming scene from the left border. auto reScene = TransitionSlideInL::create(1.0f, sc); Director::getInstance()->replaceScene(reScene); }
在goMenu()函数中的动作类都是ActionInstant的子类;
void HelloWorld::OnClickMenu(cocos2d::Ref *pSender) { MenuItem *nmitem = (MenuItem*)pSender; auto sc = Scene::create(); auto layer = MyAction::create(); layer->setTag(nmitem->getTag());// set layer‘s tag, and this should be the most important part in this func. sc->addChild(layer); auto reScene = TransitionSlideInR::create(1.0f, sc); Director::getInstance()->replaceScene(reScene); }
运行结果:
图1 HelloWorld层
图2 MyAction层
注意:这里的聚焦貌似没那么准确。
标签:
原文地址:http://www.cnblogs.com/AmitX-moten/p/4212166.html