当前位置: 首页>>代码示例>>C++>>正文


C++ Sprite3D::setVisible方法代码示例

本文整理汇总了C++中Sprite3D::setVisible方法的典型用法代码示例。如果您正苦于以下问题:C++ Sprite3D::setVisible方法的具体用法?C++ Sprite3D::setVisible怎么用?C++ Sprite3D::setVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sprite3D的用法示例。


在下文中一共展示了Sprite3D::setVisible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addChild

// on "init" you need to initialize your instance
bool Sprite3DLesson5::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(Sprite3DLesson5::menuCloseCallback, this));
    
	closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu, 1);
    
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesEnded = CC_CALLBACK_2(Sprite3DLesson5::onTouchesEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

    /////////////////////////////
    std::string filename = "res/Sprite3D/girl.c3b";
    auto sprite = Sprite3D::create(filename);
    sprite->setPosition(visibleSize.width/2 + origin.x, visibleSize.height/3 + origin.y);
    addChild(sprite);
    
    auto animation = Animation3D::create(filename);
    auto animate = Animate3D::create(animation);
    sprite->runAction(RepeatForever::create(animate));
    
    auto lfoot = Sprite::create("res/Sprite3D/circle.png");
    auto rfoot = Sprite::create("res/Sprite3D/circle.png");
    _lfoot = Sprite3D::create();
    _lfoot->addChild(lfoot);
    _lfoot->setRotation3D(Vec3(90, 0, 0));
    _rfoot = Sprite3D::create();
    _rfoot->addChild(rfoot);
    _rfoot->setRotation3D(Vec3(90, 0, 0));
    
    addChild(_lfoot);
    addChild(_rfoot);
    _lfoot->setScale(0.3f);
    _rfoot->setScale(0.3f);
    _lfoot->setVisible(false);
    _rfoot->setVisible(false);
    
    _sprite = sprite;
    
    ValueMap valuemap0;
    valuemap0["footname"] = Value("Bip001 R Toe0");
    valuemap0["lfoot"] = Value(false);
    animate->setKeyFrameUserInfo(10, valuemap0);
    valuemap0["footname"] = Value("Bip001 L Toe0");
    valuemap0["lfoot"] = Value(true);
    animate->setKeyFrameUserInfo(26, valuemap0);
    auto listener2 = EventListenerCustom::create(Animate3DDisplayedNotification, [&](EventCustom* event)
    {
        auto info = (Animate3D::Animate3DDisplayedEventInfo*)event->getUserData();
        auto footname = info->userInfo->at("footname").asString();
        bool lfoot = info->userInfo->at("lfoot").asBool();
        auto mat = _sprite->getNodeToWorldTransform() * _sprite->getSkeleton()->getBoneByName(footname)->getWorldMat();
        Sprite3D* foot = lfoot ? _lfoot : _rfoot;
        foot->setPosition3D(Vec3(mat.m[12], mat.m[13], mat.m[14]));
        foot->setVisible(true);
        cocos2d::log("frame %d", info->frame);
    });
    Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener2, -1);
    
    scheduleUpdate();
    return true;
}
开发者ID:super626,项目名称:LessonDemo,代码行数:86,代码来源:Sprite3DLesson5.cpp


注:本文中的Sprite3D::setVisible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。