Beispiel #1
0
void MainScene::animateHitPiece(Side obstacleSide)
{
    Piece* flyingPiece = dynamic_cast<Piece*>(CSLoader::createNode("Piece.csb"));
    ActionTimeline* pieceTimeline = CSLoader::createTimeline("Piece.csb");
    
    flyingPiece->setObstacleSide(obstacleSide);
    flyingPiece->setPosition(this->flyingPiecePosition);
    
    this->addChild(flyingPiece);
    this->runAction(pieceTimeline);
    
    switch (this->character->getSide()) {
        case Side::Left:
            pieceTimeline->play("moveRight", false);
            break;
        case Side::Right:
            pieceTimeline->play("moveLeft", false);
            break;
        default:
            break;
    }
    
    // on the last frame of the animation, remove the piece from the scene
    pieceTimeline->setLastFrameCallFunc([this, &flyingPiece]() {
        this->removeChild(flyingPiece);
    });
    
}
ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(const std::string&fileName, const std::string& content)
{
    // if already exists an action with filename, then return this action
    ActionTimeline* action = _animationActions.at(fileName);
    if(action)
        return action;

    rapidjson::Document doc;
    doc.Parse<0>(content.c_str());
    if (doc.HasParseError()) 
    {
        CCLOG("GetParseError %s\n", doc.GetParseError());
    }

    const rapidjson::Value& json = DICTOOL->getSubDictionary_json(doc, ACTION);

    action = ActionTimeline::create();

    action->setDuration(DICTOOL->getIntValue_json(json, DURATION));
    action->setTimeSpeed(DICTOOL->getFloatValue_json(json, TIME_SPEED, 1.0f));

    int timelineLength = DICTOOL->getArrayCount_json(json, TIMELINES);
    for (int i = 0; i<timelineLength; i++)
    {
        const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, TIMELINES, i);
        Timeline* timeline = loadTimeline(dic);

        if(timeline)
            action->addTimeline(timeline);
    }

    _animationActions.insert(fileName, action);

    return action;
}
ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(const std::string& fileName)
{
    FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
    fbs->_isSimulator = true;
    auto builder = fbs->createFlatBuffersWithXMLFileForSimulator(fileName);
    
    ActionTimeline* action = ActionTimeline::create();
    
    auto csparsebinary = GetCSParseBinary(builder->GetBufferPointer());
    auto nodeAction = csparsebinary->action();
    
    action = ActionTimeline::create();
    
    int duration = nodeAction->duration();
    action->setDuration(duration);
    
    float speed = nodeAction->speed();
    action->setTimeSpeed(speed);
    
    auto timeLines = nodeAction->timeLines();
    int timelineLength = timeLines->size();
    for (int i = 0; i < timelineLength; i++)
    {
        auto timelineFlatBuf = timeLines->Get(i);
        Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf);
        
        if (timeline)
            action->addTimeline(timeline);
    }
    
    fbs->deleteFlatBufferBuilder();
    
    return action;
}
bool WelcomeStudioScene::init(){
    if (!CCLayer::init()) {
        return false;
    }
    
    m_rootNode=NodeReader::getInstance()->createNode("Blackcat_1/Blackcat_1.ExportJson");
    ActionTimeline* action = ActionTimelineCache::getInstance()->createAction("Blackcat_1/Blackcat_1.ExportJson");
    
    
    m_rootNode->runAction(action);
    action->gotoFrameAndPlay(0, action->getDuration(), true);
    
    for (int i=0; i<m_rootNode->getChildrenCount(); i++) {
        Widget* child=(Widget*)m_rootNode->getChildren()->objectAtIndex(i);
        if (child->getTag()==-1) {
            Button* button=(Button*)UIHelper::seekWidgetByTag(child, 136);
            if(button){
                button->addTouchEventListener(this, toucheventselector(WelcomeStudioScene::touchEvent));
            }
        }
    }
    
    this->addChild(m_rootNode);
    
    return true;
}
ActionTimeline* ActionTimelineCache::createActionFromJson(const std::string& fileName)
{
    ActionTimeline* action = _animationActions.at(fileName);
    if (action == nullptr)
    {
        action = loadAnimationActionWithFile(fileName);
    }
    return action->clone();
}
ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(Data data, const std::string &fileName)
{
    ActionTimeline* action = _animationActions.at(fileName);
    if (action == NULL)
    {
        action = loadAnimationWithDataBuffer(data, fileName);
    }
    return action->clone();
}
ActionTimeline* ActionTimelineCache::createAction(const std::string& fileName)
{
    ActionTimeline* action = static_cast<ActionTimeline*>(_timelineActions->objectForKey(fileName));
    if (action == NULL)
    {
        action = loadAnimationActionWithFile(fileName);
    }
    return action->clone();
}
ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersFile(const std::string &fileName)
{
    ActionTimeline* action = _animationActions.at(fileName);
    if (action == NULL)
    {
        action = loadAnimationActionWithFlatBuffersFile(fileName);
    }
    return action->clone();
}
// ActionTimeline
ActionTimeline* ActionTimeline::create()
{
    ActionTimeline* object = new (std::nothrow) ActionTimeline();
    if (object && object->init())
    {
        object->autorelease();
        return object;
    }
    CC_SAFE_DELETE(object);
    return nullptr;
}
Beispiel #10
0
// TestActionTimelineBlendFuncFrame
void TestActionTimelineBlendFuncFrame::onEnter()
{
    ActionTimelineBaseTest::onEnter();
    Node* node = CSLoader::createNode("ActionTimeline/skeletonBlendFuncFrame.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/skeletonBlendFuncFrame.csb");
    node->runAction(action);
    node->setScale(0.2f);
    node->setPosition(VisibleRect::center());
    this->addChild(node);
    action->gotoFrameAndPlay(0);
}
Beispiel #11
0
// TestActionTimelineEase
void TestActionTimelineEase::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    Node* node = CSLoader::createNode("ActionTimeline/ActionTimelineEase.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/ActionTimelineEase.csb");
    node->runAction(action);
    action->gotoFrameAndPlay(0);

    addChild(node);
}
Beispiel #12
0
//TestTimelineProjectNode
//InnerActionFrame make InnerAction Play until action's duration or next InnerActionFrame
void TestTimelineProjectNode::onEnter()
{
    ActionTimelineBaseTest::onEnter();
    Node* node = CSLoader::createNode("ActionTimeline/TestAnimation.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/TestAnimation.csb");

    node->runAction(action);
    action->gotoFrameAndPlay(0, true);

    node->setPosition(-300, -300);
    addChild(node);
}
Beispiel #13
0
void TestActionTimelineIssueWith2SameActionInOneNode::onEnter()
{
    CCFileUtils::getInstance()->addSearchPath("ActionTimeline");
    ActionTimelineBaseTest::onEnter();

    Node* node = CSLoader::createNode("ani2.csb");
    ActionTimeline* action = CSLoader::createTimeline("ani2.csb");
    node->setPosition(Vec2(150, 100));
    node->runAction(action);
    action->gotoFrameAndPlay(0);
    this->addChild(node);
}
ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(const std::string &fileName)
{
    // if already exists an action with filename, then return this action
    ActionTimeline* action = _animationActions.at(fileName);
    if (action)
        return action;
    
    std::string path = fileName;
    
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName.c_str());
    
    CC_ASSERT(FileUtils::getInstance()->isFileExist(fullPath));
    
    Data buf = FileUtils::getInstance()->getDataFromFile(fullPath);
    
    auto csparsebinary = GetCSParseBinary(buf.getBytes());
    
    auto nodeAction = csparsebinary->action();    
    action = ActionTimeline::create();
    
    int duration = nodeAction->duration();
    action->setDuration(duration);
    float speed = nodeAction->speed();
    action->setTimeSpeed(speed);
    
    auto animationlist = csparsebinary->animationList();
    int animationcount = animationlist->size();
    for (int i = 0; i < animationcount; i++)
    {
        auto animationdata = animationlist->Get(i);
        AnimationInfo info;
        info.name = animationdata->name()->c_str();
        info.startIndex = animationdata->startIndex();
        info.endIndex = animationdata->endIndex();
        action->addAnimationInfo(info);
    }

    auto timelines = nodeAction->timeLines();
    int timelineLength = timelines->size();
    for (int i = 0; i < timelineLength; i++)
    {
        auto timelineFlatBuf = timelines->Get(i);
        Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf);
        
        if (timeline)
            action->addTimeline(timeline);
    }
    
    _animationActions.insert(fileName, action);
    
    return action;
}
Beispiel #15
0
void MainScene::triggerActionTimeline(string animationName, bool loop)
{
    // we pass "MainScene.csb" to the constructor
    // so this ActionTimeline will be able to play any of the animations
    // that we've created in MainScene.csd
    ActionTimeline* timeline = CSLoader::createTimeline("MainScene.csb");
    ERROR_HANDLING(timeline);
    
    //this->stopAllActions(); // cancel any currently running actions on MainScene
    this->runAction(timeline); // we tell MainScene to run the timeline
    timeline->play(animationName, loop);
    
}
ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(const std::string& fileName)
{
    FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
    fbs->_isSimulator = true;
    auto builder = fbs->createFlatBuffersWithXMLFileForSimulator(fileName);
    
    ActionTimeline* action = ActionTimeline::create();
    
    auto csparsebinary = GetCSParseBinary(builder->GetBufferPointer());
    auto nodeAction = csparsebinary->action();
    
    action = ActionTimeline::create();
    
    int duration = nodeAction->duration();
    action->setDuration(duration);
    
    float speed = nodeAction->speed();
    action->setTimeSpeed(speed);
    
    auto animationlist = csparsebinary->animationList();
    int animationcount = animationlist->size();
    for (int i = 0; i < animationcount; i++)
    {
        auto animationdata = animationlist->Get(i);
        AnimationInfo info;
        info.name = animationdata->name()->c_str();
        info.startIndex = animationdata->startIndex();
        info.endIndex = animationdata->endIndex();
        action->addAnimationInfo(info);
    }

    auto timeLines = nodeAction->timeLines();
    int timelineLength = timeLines->size();
    std::multimap<std::string, cocostudio::timeline::Timeline*> properTimelineMap;// order the timelines depends property name
    for (int i = 0; i < timelineLength; i++)
    {
        auto timelineFlatBuf = timeLines->Get(i);
        Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf);
        if (timeline)
        {
            properTimelineMap.insert(std::make_pair(timelineFlatBuf->property()->c_str(), timeline));
        }
    }

    for (const auto& properTimelinePair : properTimelineMap)
    {
        action->addTimeline(properTimelinePair.second);
    }
    fbs->deleteFlatBufferBuilder();
    return action;
}
Beispiel #17
0
// TestActionTimeline
void TestActionTimeline::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    Data data = FileUtils::getInstance()->getDataFromFile("ActionTimeline/DemoPlayer.csb");
    Node* node = CSLoader::createNode(data);
    ActionTimeline* action = CSLoader::createTimeline(data, "ActionTimeline/DemoPlayer.csb");
    node->runAction(action);
    action->gotoFrameAndPlay(0);

    node->setScale(0.2f);
    node->setPosition(VisibleRect::center());

    addChild(node);
}
Beispiel #18
0
//TestTimelineNodeLoadedCallback
void TestTimelineNodeLoadedCallback::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb", CC_CALLBACK_1(TestTimelineNodeLoadedCallback::nodeLoadedCallback,
                                      this));
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
    node->runAction(action);
    action->gotoFrameAndPlay(0);
    //    ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 0, 40, true);

    node->setScale(0.2f);
    node->setPosition(VisibleRect::center());

    addChild(node);
}
Beispiel #19
0
// TestTimelineAnimationList
void TestTimelineAnimationList::onEnter()
{
    ActionTimelineBaseTest::onEnter();
    Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
    cocostudio::timeline::AnimationInfo standinfo("stand", 0, 40);
    cocostudio::timeline::AnimationInfo walkinfo("walk", 41, 81);
    action->addAnimationInfo(standinfo);
    action->addAnimationInfo(walkinfo);
    node->runAction(action);
    action->play("walk", true);

    node->setScale(0.2f);
    node->setPosition(150,100);
    addChild(node);
}
Beispiel #20
0
// TestTimelinePerformance
void TestTimelinePerformance::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    for (int i = 0; i< 100; i++)
    {
        Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
        ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
        node->runAction(action);
        action->gotoFrameAndPlay(41);
//        ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 41, 81, true);

        node->setScale(0.1f);
        node->setPosition(i*2,100);
        addChild(node);
    }
}
ActionTimeline* ActionTimeline::clone() const
{
    ActionTimeline* newAction = ActionTimeline::create();
    newAction->setDuration(_duration);
    newAction->setTimeSpeed(_timeSpeed);

    for (auto timelines : _timelineMap)
    {
        for(auto timeline : timelines.second)
        {      
            Timeline* newTimeline = timeline->clone();
            newAction->addTimeline(newTimeline);
        }
    }

    return newAction;
}
Beispiel #22
0
//TestProjectNodeForSimulator
//InnerActionFrame make InnerAction Play until action's duration or next InnerActionFrame
void TestProjectNodeForSimulator::onEnter()
{
    ActionTimelineBaseTest::onEnter();
    Node* node = CSLoader::getInstance()->createNodeWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd");
    ActionTimeline* action = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator("ActionTimeline/TestAnimation.csd");

    node->runAction(action);
    action->gotoFrameAndPlay(0, true);

    node->setPosition(-300, -300);
    addChild(node);

    // test for when ProjectNode file lost
    Node* lackProjectNodefileNode = CSLoader::getInstance()->createNodeWithFlatBuffersForSimulator("ActionTimeline/TestNullProjectNode.csd");
    ActionTimeline* lackProjectNodefileAction = cocostudio::timeline::ActionTimelineCache::getInstance()->createActionWithFlatBuffersForSimulator("ActionTimeline/TestNullProjectNode.csd");
    lackProjectNodefileNode->runAction(lackProjectNodefileAction);
    lackProjectNodefileAction->gotoFrameAndPlay(0);
    addChild(lackProjectNodefileNode);
}
Beispiel #23
0
void ScenePlot::createSkin()
{
	auto skin = CSLoader::createNode(RES_MODULES_PLOT_SCENE_PLOT_CSB);
	addChild(skin);

	auto layoutBg = (Layout *)skin->getChildByName("layoutBg");
	layoutBg->addTouchEventListener([=](Ref *ref, Widget::TouchEventType type)
	{
		if (type == Widget::TouchEventType::ENDED)
		{
			ActionTimeline *actionTimeline = (ActionTimeline *)skin->getActionByTag(skin->getTag());
			if (actionTimeline == nullptr)
			{
				actionTimeline = CSLoader::createTimeline(RES_MODULES_PLOT_SCENE_PLOT_CSB);
				skin->runAction(actionTimeline);
			}

			auto animationName = "animation" + Value(_countClickCurr).asString();

			auto isAnimationInfoExists = actionTimeline->IsAnimationInfoExists(animationName);
			if (!isAnimationInfoExists)
			{
				ManagerData::getInstance()->setSaveFileExist();
				ManagerUI::getInstance()->replaceScene(TypeScene::MAIN);
				return;
			}

			if (_isPlaying)
			{
				return;
			}
			_isPlaying = true;

			actionTimeline->play(animationName, false);
			actionTimeline->setLastFrameCallFunc([=]()
			{
				_isPlaying = false;
			});

			_countClickCurr++;
		}
	});
}
Beispiel #24
0
// TestFrameEvent
void TestTimelineFrameEvent::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer.csb");
    node->runAction(action);
    action->gotoFrameAndPlay(0);
    /*
    ActionTimelineNode* node = CSLoader::createActionTimelineNode("ActionTimeline/DemoPlayer.csb", 0, 40, true);
    ActionTimeline* action = node->getActionTimeline();
     */

    node->setScale(0.2f);
    node->setPosition(150,100);
    addChild(node);

    action->setFrameEventCallFunc(CC_CALLBACK_1(TestTimelineFrameEvent::onFrameEvent, this));
}
// on "init" you need to initialize your instance
bool ChooseCharacterLayer::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    m_RootNode = static_cast<Layout*>(CSLoader::createNode("ChooseCharacterLayer.csb"));
    
    this->addChild(m_RootNode);
    
    ActionTimeline* action = CSLoader::createTimeline("ChooseCharacterLayer.csb");
    action->gotoFrameAndPlay(0);
    m_RootNode->runAction(action);
    
    if (kIsPayTest) {
        APTools::PrintUIWidgetChildrenInfo(m_RootNode);
    }
    
    auto Button_fanhui=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_fanhui"));
    if (Button_fanhui) {
        Button_fanhui->addTouchEventListener(CC_CALLBACK_2(ChooseCharacterLayer::Button_fanhui_BtnOnTouch, this));
    }
    auto Button_kaishi=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_kaishi"));
    if (Button_kaishi) {
        Button_kaishi->addTouchEventListener(CC_CALLBACK_2(ChooseCharacterLayer::Button_kaishi_BtnOnTouch, this));
    }
    
    //加粒子
    Size winSize = Director::getInstance()->getWinSize();
    ParticleSystem *kaiping=ParticleSystemQuad::create("imgs/kaipian_lizi_2.plist");
    kaiping->setPosition(apccp(0.5, 0.3));
    this->addChild(kaiping,200);
    
    setDataView();
    
    return true;
}
Beispiel #26
0
// TestTimelineExtensionData
void TestTimelineExtensionData::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    Node* node = CSLoader::createNode("ActionTimeline/TestAnimation.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/TestAnimation.csb");
    node->runAction(action);
    action->gotoFrameAndPlay(0);

    auto projectNode = node->getChildByTag(29);
    auto userdata = ((ComExtensionData*)(projectNode->getComponent("ComExtensionData")))->getCustomProperty();

    auto size = Director::getInstance()->getWinSize();
    auto label = Label::create();
    label->setString(userdata);
    label->setPosition(size.width / 2 + 300, size.height / 2 + 300);
    label->setTextColor(Color4B::ORANGE);
    node->addChild(label);
    node->setPosition(-300, -300);

    addChild(node);

}
Beispiel #27
0
//TestActionTimelineSkeleton
void TestActionTimelineSkeleton::onEnter()
{
    ActionTimelineBaseTest::onEnter();

    _changedDisplays = _changedDisplay = false;
    Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer_skeleton.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer_skeleton.csb");
    node->runAction(action);
    node->setScale(0.2f);
    node->setPosition(150, 150);
    action->gotoFrameAndPlay(0);
    addChild(node);

    auto skeletonNode = static_cast<SkeletonNode*>(node);
    const std::string weapBoneName = "Layer20";
    auto weaponHandeBone = skeletonNode->getBoneNode(weapBoneName);

    /***********   debug draw bones  *************/
    auto boneDrawsBtn = cocos2d::ui::Button::create();
    addChild(boneDrawsBtn);
    boneDrawsBtn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 30));
    boneDrawsBtn->setTitleText("Draw bone");

    skeletonNode->setDebugDrawEnabled(true);
    boneDrawsBtn->addClickEventListener([skeletonNode, this](Ref* sender)
    {
        skeletonNode->setDebugDrawEnabled(!skeletonNode->isDebugDrawEnabled());
    });


    /***************** change bone display **************************/

    // add display
    auto weapSkinToAdd = Sprite::create("ActionTimeline/testAnimationResource/girl_arms.png");
    weapSkinToAdd->setName("Knife");
    weapSkinToAdd->setPosition(Vec2(135, 23));
    weapSkinToAdd->setScale(3.0f);
    weapSkinToAdd->setRotation(86);
    weaponHandeBone->addSkin(weapSkinToAdd, false);

    // change display
    auto changeBoneDispBtn = cocos2d::ui::Button::create();
    addChild(changeBoneDispBtn);
    changeBoneDispBtn->setPosition(Vec2(VisibleRect::right().x - 60, VisibleRect::top().y - 60));
    changeBoneDispBtn->setTitleText("change bone display");
    changeBoneDispBtn->addClickEventListener([weapSkinToAdd, weaponHandeBone](Ref* sender)
    {
        // or use skeletonNode->display(bone name, skin name, hide)
        if (weapSkinToAdd->isVisible())
            weaponHandeBone->displaySkin("3", true);
        else
        {
            weaponHandeBone->displaySkin(weapSkinToAdd, true);
        }
    });


    /*************** debug draw boundingbox and transforms ***************/
    auto debugDrawNode = DrawNode::create();
    addChild(debugDrawNode);

    auto drawBoxBtn = cocos2d::ui::Button::create();
    addChild(drawBoxBtn);
    drawBoxBtn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 45));
    drawBoxBtn->setTitleText("Draw Box");


    drawBoxBtn->addClickEventListener([debugDrawNode](Ref* sender)
    {
        debugDrawNode->setVisible(!debugDrawNode->isVisible());
    });
    skeletonNode->schedule([skeletonNode, weaponHandeBone, debugDrawNode](float interval)
    {
        if (debugDrawNode->isVisible())
        {
            debugDrawNode->clear();
            // skeleton boundingbox
            auto rect = skeletonNode->getBoundingBox();
            cocos2d::Vec2 leftbottom(rect.getMinX(), rect.getMinY());
            cocos2d::Vec2 righttop(rect.getMaxX(), rect.getMaxY());
            debugDrawNode->drawRect(leftbottom, righttop, cocos2d::Color4F::YELLOW);

            // bone boundingbox
            rect = weaponHandeBone->getBoundingBox();
            leftbottom.x = rect.getMinX();
            leftbottom.y = rect.getMinY();
            righttop.x = rect.getMaxX();
            righttop.y = rect.getMaxY();
            cocos2d::Vec2 lefttop(rect.getMinX(), rect.getMaxY());
            cocos2d::Vec2 rightbottom(rect.getMaxX(), rect.getMinY());
            auto skeletonToP = skeletonNode->getNodeToParentAffineTransform();
            auto bonePtoSkeletonPTrans = AffineTransformConcat(
                                             static_cast<BoneNode*>((weaponHandeBone->getParent())
                                                                   )->getNodeToParentAffineTransform(skeletonNode),
                                             skeletonToP);
            leftbottom = PointApplyAffineTransform(leftbottom, bonePtoSkeletonPTrans);
            righttop = PointApplyAffineTransform(righttop, bonePtoSkeletonPTrans);
            lefttop = PointApplyAffineTransform(lefttop, bonePtoSkeletonPTrans);
            rightbottom = PointApplyAffineTransform(rightbottom, bonePtoSkeletonPTrans);
            debugDrawNode->drawLine(leftbottom, rightbottom, Color4F::BLUE);
            debugDrawNode->drawLine(rightbottom, righttop, Color4F::BLUE);
            debugDrawNode->drawLine(righttop, lefttop, Color4F::BLUE);
            debugDrawNode->drawLine(lefttop, leftbottom, Color4F::BLUE);

            // skin boundingbox

            // get displaying nodes
            auto currentskin = weaponHandeBone->getVisibleSkins().front();
            rect = currentskin->getBoundingBox();
            leftbottom.x = rect.getMinX();
            leftbottom.y = rect.getMinY();
            righttop.x = rect.getMaxX();
            righttop.y = rect.getMaxY();
            lefttop.x = rect.getMinX();
            lefttop.y =  rect.getMaxY();
            rightbottom.x = rect.getMaxX();
            rightbottom.y = rect.getMinY();
            auto boneToSkeletonParentTrans = AffineTransformConcat(
                                                 weaponHandeBone->getNodeToParentAffineTransform(skeletonNode), skeletonToP);
            leftbottom = PointApplyAffineTransform(leftbottom, boneToSkeletonParentTrans);
            righttop = PointApplyAffineTransform(righttop, boneToSkeletonParentTrans);
            lefttop = PointApplyAffineTransform(lefttop, boneToSkeletonParentTrans);
            rightbottom = PointApplyAffineTransform(rightbottom, boneToSkeletonParentTrans);

            debugDrawNode->drawLine(leftbottom, rightbottom, Color4F::GREEN);
            debugDrawNode->drawLine(rightbottom, righttop, Color4F::GREEN);
            debugDrawNode->drawLine(righttop, lefttop, Color4F::GREEN);
            debugDrawNode->drawLine(lefttop, leftbottom, Color4F::GREEN);
        }
    }, 0, "update debug draw");


    // change displays , can be use for dress up a skeleton
    auto changeBoneDispsBtn = cocos2d::ui::Button::create();
    addChild(changeBoneDispsBtn);
    changeBoneDispsBtn->setPosition(Vec2(VisibleRect::right().x - 60, VisibleRect::top().y - 75));
    changeBoneDispsBtn->setTitleText("change bone displays");

    std::map < std::string, std::string> boneSkinNames;
    boneSkinNames.insert(std::make_pair("Layer20", "fire"));
    boneSkinNames.insert(std::make_pair("Layer14", "fruit"));
    skeletonNode->addSkinGroup("fruitKnife", boneSkinNames);

    std::map < std::string, std::string> boneSkinNames2;
    boneSkinNames2.insert(std::make_pair("Layer20", "3"));
    boneSkinNames2.insert(std::make_pair("Layer14", "hat"));
    skeletonNode->addSkinGroup("cowboy", boneSkinNames2);

    changeBoneDispsBtn->addClickEventListener([skeletonNode, this](Ref* sender)
    {
        if (!_changedDisplays)
        {
            skeletonNode->changeSkins("fruitKnife");
            _changedDisplays = true;
        }
        else
        {
            skeletonNode->changeSkins("cowboy");
            _changedDisplays = false;
        }
    });


    /*********** test cases for bugs        **********/
    // bug: #13060 https://github.com/cocos2d/cocos2d-x/issues/13060
    // bug: bone draw at the other edge when move to outside right edge.
    BoneNode* bugtestBoneNode = BoneNode::create(500);
    bugtestBoneNode->setRotation(-10);
    bugtestBoneNode->retain();
    bugtestBoneNode->setDebugDrawEnabled(true);
    bugtestBoneNode->setPosition(Vec2(1500, VisibleRect::top().y - 90));
    auto bug13060Btn = cocos2d::ui::Button::create();
    bug13060Btn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 90));
    bug13060Btn->setTitleText("bug #13060");
    addChild(bug13060Btn);
    bug13060Btn->addClickEventListener([bugtestBoneNode, skeletonNode](Ref* sender)
    {
        if (bugtestBoneNode->getParent() == nullptr)
            skeletonNode->addChild(bugtestBoneNode);
        else
            bugtestBoneNode->removeFromParent();
        // bug fixed while bugtestBoneNode not be drawn at the bottom edge
    });

    // bug: #13005 https://github.com/cocos2d/cocos2d-x/issues/#13005
    // bug: BoneNode 's debugdraw can not be controlled by ancestor's visible
    auto leftleg = skeletonNode->getBoneNode("Layer26");
    auto bug13005Btn = cocos2d::ui::Button::create();
    addChild(bug13005Btn);
    bug13005Btn->setPosition(Vec2(VisibleRect::right().x - 30, VisibleRect::top().y - 105));
    bug13005Btn->setTitleText("bug #13005");
    bug13005Btn->addClickEventListener([leftleg](Ref* sender)
    {
        leftleg->setVisible(!leftleg->isVisible());
        // bug fixed while leftleg's child hide with leftleg's visible
    });


    /*************    Skeleton nest Skeleton test       *************/
    auto nestSkeletonBtn = cocos2d::ui::Button::create();
    nestSkeletonBtn->setTitleText("Skeleton Nest");
    nestSkeletonBtn->setPosition(Vec2(VisibleRect::right().x - 40, VisibleRect::top().y - 120));
    addChild(nestSkeletonBtn);
    auto nestSkeleton = static_cast<SkeletonNode*>(CSLoader::createNode("ActionTimeline/DemoPlayer_skeleton.csb"));
    nestSkeleton->retain();
    ActionTimeline* nestSkeletonAction = action->clone();
    nestSkeletonAction->retain();
    nestSkeleton->runAction(nestSkeletonAction);
    nestSkeleton->setScale(0.2f);
    nestSkeleton->setPosition(150, 300);
    nestSkeletonAction->gotoFrameAndPlay(0);
    // show debug draws, or comment this for hide bones draws
    for (auto& nestbonechild : nestSkeleton->getAllSubBonesMap())
    {
        nestbonechild.second->setDebugDrawEnabled(true);
    }

    nestSkeletonBtn->addClickEventListener([leftleg, nestSkeleton, nestSkeletonAction](Ref* sender)
    {
        if (nestSkeleton->getParent() == nullptr)
        {
            leftleg->addChild(nestSkeleton);
        }
        else
        {
            nestSkeleton->removeFromParentAndCleanup(false);
        }
    });
}
Beispiel #28
0
// on "init" you need to initialize your instance
bool MainMapScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto seq=Sequence::create(RotateBy::create(1, 10), NULL);
    auto replay=RepeatForever::create(seq);
    
    m_RootNode = static_cast<Layout*>(CSLoader::createNode("MainMapScene.csb"));
    this->addChild(m_RootNode);
    
    ActionTimeline* action = CSLoader::createTimeline("MainMapScene.csb");
    action->gotoFrameAndPlay(0);
    m_RootNode->runAction(action);
    
    if (kIsPayTest) {
        APTools::PrintUIWidgetChildrenInfo(m_RootNode);
    }
    //总战斗力
    m_SumPower=dynamic_cast<TextBMFont*>(Helper::seekWidgetByName(m_RootNode, "BitmapFontLabel_zhanli"));
    
    for (int i=1; i<=3; i++) {
        auto imgName=__String::createWithFormat("Image_yuan_%d",i);
        auto img=dynamic_cast<ImageView*>(Helper::seekWidgetByName(m_RootNode, imgName->getCString()));
        if (img) {
            img->runAction(replay->clone());
        }
    }
    for (int i=1; i<=2; i++) {
        auto btnName=__String::createWithFormat("Button_tianjia_%d", i);
        auto btn=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, btnName->getCString()));
        if (btn) {
            btn->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_Shop_BtnOnTouch, this));
        }
    }
    auto Button_guanka_3=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_guanka_3"));
    if (Button_guanka_3) {
        Button_guanka_3->setTag(3);
        Button_guanka_3->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_play_BtnOnTouch, this));
    }
    auto Button_guanka_2=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_guanka_2"));
    if (Button_guanka_2) {
        Button_guanka_2->setTag(2);
        Button_guanka_2->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_play_BtnOnTouch, this));
    }
    auto Button_guanka_1=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_guanka_1"));
    if (Button_guanka_1) {
        Button_guanka_1->setTag(1);
        Button_guanka_1->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_play_BtnOnTouch, this));
    }
    
    auto Button_DayReward=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_gongneng_6"));
    if (Button_DayReward) {
        Button_DayReward->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_DayReward_BtnOnTouch, this));
    }
    auto Button_Equip=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_gongneng_1"));
    if (Button_Equip) {
        Button_Equip->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_Equip_BtnOnTouch, this));
    }
    auto Button_EquipUpgrade=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_gongneng_2"));
    if (Button_EquipUpgrade) {
        Button_EquipUpgrade->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_EquipUpgrade_BtnOnTouch, this));
    }
    auto Button_SkillUpgrade=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_gongneng_3"));
    if (Button_SkillUpgrade) {
        Button_SkillUpgrade->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_SkillUpgrade_BtnOnTouch, this));
    }
    auto Button_Lottery=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_gongneng_4"));
    if (Button_Lottery) {
        Button_Lottery->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_Lottery_BtnOnTouch, this));
    }
    auto Button_Shop=dynamic_cast<ui::Button*>(Helper::seekWidgetByName(m_RootNode, "Button_gongneng_5"));
    if (Button_Shop) {
        Button_Shop->addTouchEventListener(CC_CALLBACK_2(MainMapScene::Button_Shop_BtnOnTouch, this));
    }
    
    tCoin=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_jinbishuliang"));
    tDiamond=dynamic_cast<ui::Text*>(Helper::seekWidgetByName(m_RootNode, "Text_zuanshishu"));
    
    updateLabel();
    
    SoundBLL::getInstance()->playbackground(kStartMusic);
    
    return true;
}
Beispiel #29
0
//TestAnimationClipEndCallBack
void TestAnimationClipEndCallBack::onEnter()
{
    ActionTimelineBaseTest::onEnter();
    Node* node = CSLoader::createNode("ActionTimeline/DemoPlayer_skeleton.csb");
    ActionTimeline* action = CSLoader::createTimeline("ActionTimeline/DemoPlayer_skeleton.csb");
    node->runAction(action);
    node->setScale(0.2f);
    node->setPosition(150, 150);

    // test for frame end call back
    action->addFrameEndCallFunc(5, "CallBackAfterFifthFrame", [this] {
        auto text = ui::Text::create();
        text->setString("CallBackAfterFifthFrame");
        text->setPosition(Vec2(100, 40));
        text->setLocalZOrder(1000);
        this->runAction(Sequence::create(
        CallFunc::create([this, text]{this->addChild(text); }),
        DelayTime::create(3),
        CallFunc::create([text]{text->removeFromParent(); }),
        nullptr));
    });
    action->addFrameEndCallFunc(5, "AnotherCallBackAfterFifthFrame", [this] {
        auto text = ui::Text::create();
        text->setString("AnotherCallBackAfterFifthFrame");
        text->setPosition(Vec2(100, 70));
        this->runAction(Sequence::create(
        CallFunc::create([this, text]{this->addChild(text); }),
        DelayTime::create(3),
        CallFunc::create([text]{text->removeFromParent(); }),
        nullptr));
    });
    action->addFrameEndCallFunc(7, "CallBackAfterSenvnthFrame", [this] {
        auto text = ui::Text::create();
        text->setString("CallBackAfterSenvnthFrame");
        text->setPosition(Vec2(100, 100));
        this->runAction(Sequence::create(
        CallFunc::create([this, text]{this->addChild(text); }),
        DelayTime::create(3),
        CallFunc::create([text]{text->removeFromParent(); }),
        nullptr));
    });

    // test for animation clip end call back
    action->setAnimationEndCallFunc("stand", [this] {
        auto text = ui::Text::create();
        text->setString("CallBackAfterStandAnimationClip");
        text->setPosition(Vec2(100, 130));
        this->runAction(Sequence::create(
        CallFunc::create([this, text]{this->addChild(text); }),
        DelayTime::create(3),
        CallFunc::create([text]{text->removeFromParent(); }),
        nullptr));
    });

    AnimationClip animClip("testClip", 3, 13);
    animClip.clipEndCallBack = ([this,node] {
        auto text = ui::Text::create();
        text->setString("testClip");
        text->setPosition(Vec2(100, 140));
        this->runAction(Sequence::create(
        CallFunc::create([this, text]{this->addChild(text); }),
        DelayTime::create(3),
        CallFunc::create([text]{text->removeFromParent(); }),
        nullptr));
    });
    action->addAnimationInfo(animClip);

    action->setTimeSpeed(0.2f);
    addChild(node);
    action->gotoFrameAndPlay(0);
}