TerminalMessageView* TerminalMessageView::create() { auto ret = new TerminalMessageView(); if (!ret) { CC_SAFE_DELETE(ret); return nullptr; } ret->autorelease(); // 開始位置固定 ret->setAnchorPoint(Point(0, 0)); ret->setPosition(16, 56); ret->setScale(2.0f); auto msg_label = Label::createWithBMFont("fonts/message_font.fnt", ""); msg_label->getTexture()->setAliasTexParameters(); msg_label->setAnchorPoint(Point(0, 1)); msg_label->setPosition(8, 40); msg_label->setColor(Color3B(0, 255, 30)); msg_label->setWidth(132); msg_label->setLineBreakWithoutSpace(true); ret->addChild(msg_label); ret->setMsgLabel(msg_label); ret->setVisible(false); ret->setStringIdx(0); ret->setMsg(""); return ret; }
// on "init" you need to initialize your instance bool 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); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label auto label = Label::create(); label->setDimensions(400, 100); label->setLineBreakWithoutSpace(true); //label->setString("123456789012345678901234567890 123456789012345678901234567890 12345678901234567890"); label->setSystemFontName("Arial"); label->setSystemFontSize(24); // position the label on the center of the screen //label->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height - label->getContentSize().height)); label->setAnchorPoint(Vec2(0, 1)); label->setPosition(Vec2(100,100)); // add the label as a child to this layer this->addChild(label, 1); /*TintTest*/ /* // add "HelloWorld" splash screen" auto sprite = Sprite::create("images/380.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); sprite->setColor(Color3B(0, 255, 0)); // add the sprite as a child to this layer this->addChild(sprite, 1); sprite->runAction(Sequence::createWithTwoActions(TintTo::create(3, 255, 255, 0), TintTo::create(3, 255, 0, 0)));*/ /* MonsterHeadSprite *monster = MonsterHeadSprite::create("и╜ажа╜йС"); monster->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y)); this->addChild(monster, 0); DigitSprite* digit = DigitSprite::create(); digit->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y)); this->addChild(digit, 0); digit->showDigit(21);*/ /* //dialogue layer test Node* stencil = Node::create(); auto clip1 = LayerColor::create(Color4B::BLACK, 24, 24); clip1->setPosition(Vec2(100,76)); stencil->addChild(clip1); ClippingNode* clippingNode = ClippingNode::create(stencil); clippingNode->addChild(sprite); addChild(clippingNode, 2);*/ /* //CharacterLayer test CharacterLayer *clayer = CharacterLayer::create(); addChild(clayer, 1, 1);*/ /*choice menu layer auto layer = ChoiceLayer::create(); layer->setAnchorPoint(Vec2(0.5, 0.5)); layer->setPosition(Vec2(400, 300)); addChild(layer, 2, 2);*/ /*Read script file FileUtils::getInstance()->addSearchPath("scripts"); if (!FileUtils::getInstance()->isFileExist("script.rpy")) { CCLOG("cannot find file: script.rpy."); } string s = FileUtils::getInstance()->getStringFromFile("script.rpy"); size_t pos = s.find_first_of("\r\n"); list<string> stmts = CommonUtils::splitString(s, "\r\n"); label->setString(stmts.front()); */ return true; }
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } CReadFile::getInstance()->init(); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto closeItem = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png" , CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setScale(0.3f); closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2-310 , origin.y + closeItem->getContentSize().height/2+160)); auto closeItem1 = MenuItemImage::create( "picture/blue1_menu.png", "picture/blue2_menu.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback1, this)); closeItem1->setScale(0.5f); closeItem1->setPosition(Vec2(origin.x + visibleSize.width - closeItem1->getContentSize().width/2-310 , origin.y + closeItem1->getContentSize().height/2+330)); auto SetMenu = MenuItemImage::create( "picture/shezhi2_cover.png", "picture/shezhi1_cover.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback3, this)); SetMenu->setScale(0.8f); SetMenu->setPosition(Vec2(origin.x + visibleSize.width - SetMenu->getContentSize().width/2-390 , origin.y + SetMenu->getContentSize().height/2+260)); auto menu = Menu::create(closeItem,closeItem1,SetMenu, NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu, 1); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto label = Label::createWithTTF(Tools::Unicode2Utf8(L"开始游戏"), "fonts/msyh.ttc", 24); #else auto label = Label::createWithTTF("开始游戏", "fonts/msyh.ttc", 24); #endif label->setPosition(Vec2(closeItem1->getPositionX(), closeItem1->getPositionY())); label->setScale(0.8f); this->addChild(label, 1); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto label1 = Label::createWithTTF(Tools::Unicode2Utf8(L"退出"), "fonts/msyh.ttc", 24); #else auto label1 = Label::createWithTTF("退出", "fonts/msyh.ttc", 24); #endif label1->setPosition(Vec2(closeItem->getPositionX(), closeItem->getPositionY())); label1->setScale(0.8f); this->addChild(label1,1); auto sprite = Sprite::create("picture/shumabaobei.jpg"); Size sprSize = sprite->getContentSize(); sprite->setScaleX(visibleSize.width/sprSize.width); sprite->setScaleY(visibleSize.height/sprSize.height); sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(sprite, 0); auto logo = Sprite::create("picture/logo.png"); Size logoSize = logo->getContentSize(); auto spark = Sprite::create("picture/spark.png"); spark->setPosition(-logoSize.width,0); auto clippingNode = ClippingNode::create(); clippingNode->setPosition(500,560); this->addChild(clippingNode); clippingNode->setAlphaThreshold(0.05f); clippingNode->setContentSize(logoSize); clippingNode->setStencil(logo); clippingNode->addChild(logo,1); clippingNode->addChild(spark,2); auto moveAction = MoveTo::create(2.0f,Vec2(logoSize.width,0)); auto moveBackAction = MoveTo::create(2.0f,Vec2(-logoSize.width,0)); spark->runAction(RepeatForever::create(Sequence::create(moveAction,moveBackAction,NULL))); if (CReadFile::getInstance()->getshuomingkg()) { CReadFile::getInstance()->setshuomingkg(false); CSound::getInstance()->playBG("Butter-Fly.mp3",CSound::getInstance()->getIsPlay()); CSound::getInstance()->setIsPlay(true); auto shuominglayer = LayerColor::create(Color4B(120,120,120,200)); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 auto wenzi = Label::createWithTTF(Tools::Unicode2Utf8(L"欢迎来到宝库设计的数码宝贝记忆消除游戏"),"fonts/msyh.ttc", 28); #else auto wenzi = Label::createWithTTF("欢迎来到宝库设计的数码宝贝记忆消除游戏","fonts/msyh.ttc", 28); #endif wenzi->setMaxLineWidth(460); wenzi->setLineBreakWithoutSpace(true); wenzi->setPosition(480,520); wenzi->setColor(ccc3(0,0,0)); shuominglayer->runAction(FadeOut::create(5)); wenzi->runAction(FadeOut::create(3)); shuominglayer->addChild(wenzi,2); this->addChild(shuominglayer,2); } return true; }