仿TestCpp實現Layout頁面轉場效果,testcpp頁面切換

來源:互聯網
上載者:User

仿TestCpp實現Layout頁面轉場效果,testcpp頁面切換

//HelloWorld.h#include "cocos2d.h"#include "ui/CocosGUI.h"#include "First.h"#include "Second.h"#include "Third.h"USING_NS_CC;using namespace ui;enum Tag{    FIRST = 1,    SECOND,    THIRD};class HelloWorld : public cocos2d::Layer{public:    // there's no 'id' in cpp, so we recommend returning the class instance pointer    static cocos2d::Scene* createScene();    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone    virtual bool init();      Size winSize;    First* first;    Second* second;    Third* third;    void createLayout(int tag);    // a selector callback    void menuCloseCallback(cocos2d::Ref* pSender);    void touchEvent(Ref *pSender, cocos2d::ui::Widget::TouchEventType type);//    void touchEvent(Ref* pSender,cocos2d::ui::Widget::TouchEventType type);    // implement the "static create()" method manually    CREATE_FUNC(HelloWorld);};


//HelloWorld.cpp#include "HelloWorldScene.h"#define MAX_LAYER 3;USING_NS_CC;Scene* HelloWorld::createScene(){    // 'scene' is an autorelease object    auto scene = Scene::create();        // 'layer' is an autorelease object    auto layer = HelloWorld::create();    // add layer as a child to scene    scene->addChild(layer);    // return the scene    return scene;}static int sceneIdx = -1;Layout* createActionManagerLayer(int nIndex){    log("sceneIdx = %d",nIndex);    switch(nIndex)    {        case 0: return First::create();        case 1: return Second::create();        case 2: return Third::create();    }        return NULL;}Layout* nextActionManagerAction();Layout* backActionManagerAction();Layout* restartActionManagerAction();Layout* nextActionManagerAction(){    sceneIdx++;    sceneIdx = sceneIdx % MAX_LAYER;        auto layer = createActionManagerLayer(sceneIdx);//    layer->autorelease();        return layer;}Layout* backActionManagerAction(){    sceneIdx--;    int total = MAX_LAYER;    if( sceneIdx < 0 )        sceneIdx += total;        auto layer = createActionManagerLayer(sceneIdx);//    layer->autorelease();        return layer;}Layout* restartActionManagerAction(){    auto layer = createActionManagerLayer(sceneIdx);//    layer->autorelease();        return layer;} // on "init" you need to initialize your instancebool HelloWorld::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(HelloWorld::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);    winSize = Director::getInstance()->getWinSize();        auto layout = Layout::create();    layout->setSize(Size(winSize.width,winSize.height/4));    layout->setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);    layout->setBackGroundColor(Color3B::WHITE);    layout->ignoreAnchorPointForPosition(false);    layout->setAnchorPoint(Vec2::ANCHOR_MIDDLE_TOP);    layout->setPosition(Vec2(winSize.width/2,winSize.height));    addChild(layout);        auto image1 = ui::ImageView::create("b2.png");    image1->setTag(FIRST);    image1->setPosition(Vec2(layout->getSize().width/4,layout->getSize().height/2));    image1->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));    layout->addChild(image1);            auto image2 = ui::ImageView::create("r2.png");    image2->setTag(SECOND);    image2->setPosition(Vec2(layout->getSize().width/2,layout->getSize().height/2));    image2->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));    layout->addChild(image2);            auto image3 = ui::ImageView::create("f2.png");    image3->setTag(THIRD);    image3->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));    image3->setPosition(Vec2(layout->getSize().width/4*3,layout->getSize().height/2));    layout->addChild(image3);        auto first = First::create();    first->setTag(10);    first->setPosition(Vec2(winSize.width/2,winSize.width/4));    addChild(first);        return true;}void HelloWorld::touchEvent(cocos2d::Ref *pSender, cocos2d::ui::Widget::TouchEventType type){    auto tag = static_cast<ui::ImageView*>(pSender)->getTag();    log("tag=%d",tag);    auto child = getChildByTag(10);    if(child != nullptr)    {        removeChildByTag(10);    }    switch(tag)    {        case FIRST:        {            log("First");            auto temp = backActionManagerAction();            temp->setTag(10);            temp->setPosition(Vec2(winSize.width/2,winSize.width/4));            addChild(temp);            break;        }        case SECOND:        {            log("Second");            auto temp = restartActionManagerAction();            temp->setPosition(Vec2(winSize.width/2,winSize.width/4));            temp->setTag(10);            addChild(temp);            break;        }        case THIRD:        {            log("Third");            auto temp = nextActionManagerAction();            temp->setPosition(Vec2(winSize.width/2,winSize.width/4));            temp->setTag(10);            addChild(temp);            break;        }        default:        {                        break;        }    }}void HelloWorld::menuCloseCallback(Ref* pSender){#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");    return;#endif    Director::getInstance()->end();#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)    exit(0);#endif}

//First.h#include "cocos2d.h"#include "ui/CocosGUI.h"USING_NS_CC;using namespace ui;class First : public Layout{public:    CREATE_FUNC(First);    virtual bool init();    void touchEvent(Ref* pSender,cocos2d::ui::Widget::TouchEventType type);};

//First.cpp#include "First.h"bool First::init(){    bool bRet = false;    do{        CC_BREAK_IF(!Layout::init());                auto winSize = Director::getInstance()->getWinSize();        setSize(Size(winSize.width/2,winSize.height/4));        setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);        setBackGroundColor(Color3B::GREEN);        ignoreAnchorPointForPosition(false);        setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);        auto text = Text::create("1","",30);        text->setColor(Color3B::WHITE);        text->setPosition(Vec2(getSize().width/2,getSize().height/2));        addChild(text);                bRet = true;    }while(0);    return bRet;}void First::touchEvent(cocos2d::Ref *pSender, cocos2d::ui::Widget::TouchEventType type){    auto temp =  static_cast<ui::ImageView*>(pSender);    log("tag = %d",temp->getTag());}

//Second.h#include "cocos2d.h"#include "ui/CocosGUI.h"USING_NS_CC;using namespace ui;class Second : public Layout{public:    CREATE_FUNC(Second);    virtual bool init();    void touchEvent(Ref* pSender,cocos2d::ui::Widget::TouchEventType type);};

//Second.cpp#include "Second.h"bool Second::init(){    bool bRet = false;    do{        CC_BREAK_IF(!Layout::init());                auto winSize = Director::getInstance()->getWinSize();        setSize(Size(winSize.width/2,winSize.height/4));        setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);        setBackGroundColor(Color3B::GREEN);        ignoreAnchorPointForPosition(false);        setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);        auto text = Text::create("2","",30);        text->setColor(Color3B::WHITE);        text->setPosition(Vec2(getSize().width/2,getSize().height/2));        addChild(text);                bRet = true;    }while(0);    return bRet;}void Second::touchEvent(cocos2d::Ref *pSender, cocos2d::ui::Widget::TouchEventType type){    auto temp =  static_cast<ui::ImageView*>(pSender);    log("tag = %d",temp->getTag());}

//Third.h#include "cocos2d.h"#include "ui/CocosGUI.h"USING_NS_CC;using namespace ui;class Third : public Layout{public:    CREATE_FUNC(Third);    virtual bool init();    void touchEvent(Ref* pSender,cocos2d::ui::Widget::TouchEventType type);};

//Third.cpp#include "Third.h"bool Third::init(){    bool bRet = false;    do{        CC_BREAK_IF(!Layout::init());        auto winSize = Director::getInstance()->getWinSize();        setBackGroundColorType(cocos2d::ui::Layout::BackGroundColorType::SOLID);        setBackGroundColor(Color3B::GREEN);        setSize(Size(winSize.width/2,winSize.height/4));        ignoreAnchorPointForPosition(false);        setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);        auto text = Text::create("3","",30);        text->setColor(Color3B::WHITE);        text->setPosition(Vec2(getSize().width/2,getSize().height/2));        addChild(text);                bRet = true;    }while(0);    return bRet;}void Third::touchEvent(cocos2d::Ref *pSender, cocos2d::ui::Widget::TouchEventType type){    auto temp =  static_cast<ui::ImageView*>(pSender);    log("tag = %d",temp->getTag());}



CAD開啟圖紙時出現“內部錯誤:!layoutcpp@135:eInvalidInput”怎辦?中午剛儲存的,XP系統2006版

1、看看有沒有 .bak備份檔案,改名xxx.bak為sss.dwg開啟試試。
2、進入cad,菜單“檔案”——“繪圖公用程式”——“修複”找到你打不開的檔案試試。
3、拷貝你的.dwg和.bak檔案到別的電腦試試。也可發給我
 
魯班土建開啟出現“內部錯誤: !layoutcpp@135: eInvalidInput” 怎解決

是開啟工程時出現的,還是一開啟土建土建就出現的錯誤提示?
如果是開啟工程的,那就用備份檔案試試,備份檔案是壓縮包解決後就可以了;
這個提示估計是開啟軟體時出現的,CAD需要重新安裝,安裝時要換個磁碟目錄,然後魯班軟體也有重新安裝,安裝好了,要在殺毒軟體裡添加白名單,不然會出現載入到90%不動。
也有可能是高版本的CAD2011平台轉到了低版本的CAD2006出現的,這樣的可以重新再另存就可以了。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.