From f9b747cf1f7c5fea216ad4253953f2c26a155e40 Mon Sep 17 00:00:00 2001 From: chuanweizhang2013 Date: Thu, 5 Jun 2014 18:03:38 +0800 Subject: [PATCH] modify runtime --- .../runtime-src/Classes/runtime/Runtime.cpp | 120 +++++++++--------- 1 file changed, 57 insertions(+), 63 deletions(-) diff --git a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp index 1812d70dd9..b46a7c27dd 100644 --- a/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp +++ b/templates/lua-template-runtime/frameworks/runtime-src/Classes/runtime/Runtime.cpp @@ -102,6 +102,11 @@ public: #include "ResData.h" int designWidth = 1280; int designHeight = 800; + string fontName = "Arial"; + if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + { + fontName = "DroidSans"; + } Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designWidth,designHeight,ResolutionPolicy::EXACT_FIT); Image* imagebg = new Image(); imagebg->initWithImageData(__landscapePngData, sizeof(__landscapePngData)); @@ -112,52 +117,50 @@ public: } Texture2D* texturebg = Director::getInstance()->getTextureCache()->addImage(imagebg, "play_background"); auto background = Sprite::createWithTexture(texturebg); - if (background) - { - background->setAnchorPoint(Vec2(0,0)); - addChild(background,9999); - } + background->setAnchorPoint(Vec2(0,0)); + addChild(background,9000); + + // variable of below is"play" button position. + int portraitX = 400; + int portraitY = 500; + int lanscaptX = 902; + int lanscaptY = 400; Image* imageplay = new Image(); imageplay->initWithImageData(__playEnablePngData, sizeof(__playEnablePngData)); Texture2D* textureplay = Director::getInstance()->getTextureCache()->addImage(imageplay, "play_enable"); auto playSprite = Sprite::createWithTexture(textureplay); - if (playSprite) - { - playSprite->setPosition(Vec2(902,400)); - addChild(playSprite,9999); - }else - { - auto labelPlay = LabelTTF::create("play", "Arial", 108); - auto menuItem = MenuItemLabel::create(labelPlay, CC_CALLBACK_1(ConnectWaitLayer::playerCallback, this)); - auto menu = Menu::create(menuItem, NULL); + playSprite->setPosition(Vec2(lanscaptX,lanscaptY)); + addChild(playSprite,9999); - menu->setPosition( Point::ZERO ); - menuItem->setPosition(Vec2(902,400)); - if (!ConfigParser::getInstance()->isLanscape()) menuItem->setPosition(Vec2(400,500)); - addChild(menu, 1); - } Image* imageShine = new Image(); imageShine->initWithImageData(__shinePngData, sizeof(__shinePngData)); - Texture2D* textureShine = Director::getInstance()->getTextureCache()->addImage(imageShine, "play_enable"); + Texture2D* textureShine = Director::getInstance()->getTextureCache()->addImage(imageShine, "Shine"); auto shineSprite = Sprite::createWithTexture(textureShine); - if (shineSprite) - { - shineSprite->setPosition(Vec2(902,400)); - shineSprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(FadeIn::create(0.6f),FadeOut::create(0.8f)))); - addChild(shineSprite,9999); - } + shineSprite->setOpacity(0); + shineSprite->setPosition(Vec2(lanscaptX,lanscaptY)); + Vector arrayOfActions; + arrayOfActions.pushBack(DelayTime::create(0.5)); + arrayOfActions.pushBack(FadeTo::create(1.0f,178)); + arrayOfActions.pushBack(FadeTo::create(1.0f,255)); + arrayOfActions.pushBack(FadeTo::create(1.0f,178)); + arrayOfActions.pushBack(FadeTo::create(1.0f,0)); + arrayOfActions.pushBack(DelayTime::create(0.5)); + Sequence * arrayAction = Sequence::create(arrayOfActions); + shineSprite->runAction(RepeatForever::create(Sequence::create(arrayOfActions))); + addChild(shineSprite,9998); + string strip = getIPAddress(); char szIPAddress[512]={0}; sprintf(szIPAddress, "IP: %s",strip.c_str()); - auto IPlabel = Label::create(szIPAddress, "Arial", 72); + auto IPlabel = Label::create(szIPAddress, fontName.c_str(), 72); IPlabel->setAnchorPoint(Vec2(0,0)); int spaceSizex = 72; int spaceSizey = 200; IPlabel->setPosition( Point(VisibleRect::leftTop().x+spaceSizex, VisibleRect::top().y -spaceSizey) ); - addChild(IPlabel, 9999); + addChild(IPlabel, 9001); s_strFile = "waiting for file transfer ..."; if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM) @@ -165,56 +168,47 @@ public: s_strFile = "waiting for debugger to connect ..."; } - _labelUploadFile = Label::create(s_strFile.c_str(), "Arial", 36); + _labelUploadFile = Label::create(s_strFile.c_str(), fontName.c_str(), 36); _labelUploadFile->setAnchorPoint(Vec2(0,0)); _labelUploadFile->setPosition( Point(VisibleRect::leftTop().x+spaceSizex, IPlabel->getPositionY()-spaceSizex) ); _labelUploadFile->setAlignment(TextHAlignment::LEFT); - addChild(_labelUploadFile, 10000); + addChild(_labelUploadFile, 9002); if (!ConfigParser::getInstance()->isLanscape()) { - if (playSprite) playSprite->setPosition(400,500); - if (shineSprite) shineSprite->setPosition(400,500); + if (playSprite) playSprite->setPosition(portraitX,portraitY); + if (shineSprite) shineSprite->setPosition(portraitX,portraitY); _labelUploadFile->setAlignment(TextHAlignment::LEFT); } - if (playSprite) - { - auto listener = EventListenerTouchOneByOne::create(); - listener->onTouchBegan = [](Touch* touch, Event *event)->bool{ - auto target = static_cast(event->getCurrentTarget()); - Vec2 point = target->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); - auto rect = Rect(0, 0, target->getContentSize().width, target->getContentSize().height); - if (!rect.containsPoint(point)) return false; - target->stopAllActions(); - target->runAction(Sequence::createWithTwoActions(ScaleBy::create(0.05f, 0.9f),ScaleTo::create(0.125f, 1))); - return true; - }; - listener->onTouchEnded = [](Touch* touch, Event *event){ - auto target = static_cast(event->getCurrentTarget()); - Vec2 point = target->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); - auto rect = Rect(0, 0, target->getContentSize().width, target->getContentSize().height); - if (!rect.containsPoint(point)) return; - startScript(""); - }; - _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, playSprite); - } + auto listener = EventListenerTouchOneByOne::create(); + listener->onTouchBegan = [](Touch* touch, Event *event)->bool{ + auto target = static_cast(event->getCurrentTarget()); + Vec2 point = target->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); + auto rect = Rect(0, 0, target->getContentSize().width, target->getContentSize().height); + if (!rect.containsPoint(point)) return false; + target->stopAllActions(); + target->runAction(Sequence::createWithTwoActions(ScaleBy::create(0.05f, 0.9f),ScaleTo::create(0.125f, 1))); + return true; + }; + listener->onTouchEnded = [](Touch* touch, Event *event){ + auto target = static_cast(event->getCurrentTarget()); + Vec2 point = target->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); + auto rect = Rect(0, 0, target->getContentSize().width, target->getContentSize().height); + if (!rect.containsPoint(point)) return; + startScript(""); + }; + _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, playSprite); + this->scheduleUpdate(); } - void playerCallback(Object* sender) - { - startScript(""); - } - - void update( float fDelta ) { - s_FileNameMutex.lock(); - if (s_strFile.length() < 1) - { + if (s_strFile.length()<1) return; - } + + s_FileNameMutex.lock(); _labelUploadFile->setString(s_strFile); s_FileNameMutex.unlock(); }