Merge pull request #33 from chuanweizhang2013/v3luaruntime

modify runtime
This commit is contained in:
cocoscodeide 2014-06-05 20:21:53 +08:00
commit 628553b4b1
1 changed files with 57 additions and 63 deletions

View File

@ -102,6 +102,11 @@ public:
#include "ResData.h" #include "ResData.h"
int designWidth = 1280; int designWidth = 1280;
int designHeight = 800; int designHeight = 800;
string fontName = "Arial";
if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
{
fontName = "DroidSans";
}
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designWidth,designHeight,ResolutionPolicy::EXACT_FIT); Director::getInstance()->getOpenGLView()->setDesignResolutionSize(designWidth,designHeight,ResolutionPolicy::EXACT_FIT);
Image* imagebg = new Image(); Image* imagebg = new Image();
imagebg->initWithImageData(__landscapePngData, sizeof(__landscapePngData)); imagebg->initWithImageData(__landscapePngData, sizeof(__landscapePngData));
@ -112,52 +117,50 @@ public:
} }
Texture2D* texturebg = Director::getInstance()->getTextureCache()->addImage(imagebg, "play_background"); Texture2D* texturebg = Director::getInstance()->getTextureCache()->addImage(imagebg, "play_background");
auto background = Sprite::createWithTexture(texturebg); auto background = Sprite::createWithTexture(texturebg);
if (background)
{
background->setAnchorPoint(Vec2(0,0)); background->setAnchorPoint(Vec2(0,0));
addChild(background,9999); 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(); Image* imageplay = new Image();
imageplay->initWithImageData(__playEnablePngData, sizeof(__playEnablePngData)); imageplay->initWithImageData(__playEnablePngData, sizeof(__playEnablePngData));
Texture2D* textureplay = Director::getInstance()->getTextureCache()->addImage(imageplay, "play_enable"); Texture2D* textureplay = Director::getInstance()->getTextureCache()->addImage(imageplay, "play_enable");
auto playSprite = Sprite::createWithTexture(textureplay); auto playSprite = Sprite::createWithTexture(textureplay);
if (playSprite) playSprite->setPosition(Vec2(lanscaptX,lanscaptY));
{
playSprite->setPosition(Vec2(902,400));
addChild(playSprite,9999); 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);
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(); Image* imageShine = new Image();
imageShine->initWithImageData(__shinePngData, sizeof(__shinePngData)); 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); auto shineSprite = Sprite::createWithTexture(textureShine);
if (shineSprite) shineSprite->setOpacity(0);
{ shineSprite->setPosition(Vec2(lanscaptX,lanscaptY));
shineSprite->setPosition(Vec2(902,400)); Vector<FiniteTimeAction*> arrayOfActions;
shineSprite->runAction(RepeatForever::create(Sequence::createWithTwoActions(FadeIn::create(0.6f),FadeOut::create(0.8f)))); arrayOfActions.pushBack(DelayTime::create(0.5));
addChild(shineSprite,9999); 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(); string strip = getIPAddress();
char szIPAddress[512]={0}; char szIPAddress[512]={0};
sprintf(szIPAddress, "IP: %s",strip.c_str()); 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)); IPlabel->setAnchorPoint(Vec2(0,0));
int spaceSizex = 72; int spaceSizex = 72;
int spaceSizey = 200; int spaceSizey = 200;
IPlabel->setPosition( Point(VisibleRect::leftTop().x+spaceSizex, VisibleRect::top().y -spaceSizey) ); IPlabel->setPosition( Point(VisibleRect::leftTop().x+spaceSizex, VisibleRect::top().y -spaceSizey) );
addChild(IPlabel, 9999); addChild(IPlabel, 9001);
s_strFile = "waiting for file transfer ..."; s_strFile = "waiting for file transfer ...";
if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM) if (CC_PLATFORM_WIN32 == CC_TARGET_PLATFORM || CC_PLATFORM_MAC == CC_TARGET_PLATFORM)
@ -165,21 +168,19 @@ public:
s_strFile = "waiting for debugger to connect ..."; 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->setAnchorPoint(Vec2(0,0));
_labelUploadFile->setPosition( Point(VisibleRect::leftTop().x+spaceSizex, IPlabel->getPositionY()-spaceSizex) ); _labelUploadFile->setPosition( Point(VisibleRect::leftTop().x+spaceSizex, IPlabel->getPositionY()-spaceSizex) );
_labelUploadFile->setAlignment(TextHAlignment::LEFT); _labelUploadFile->setAlignment(TextHAlignment::LEFT);
addChild(_labelUploadFile, 10000); addChild(_labelUploadFile, 9002);
if (!ConfigParser::getInstance()->isLanscape()) if (!ConfigParser::getInstance()->isLanscape())
{ {
if (playSprite) playSprite->setPosition(400,500); if (playSprite) playSprite->setPosition(portraitX,portraitY);
if (shineSprite) shineSprite->setPosition(400,500); if (shineSprite) shineSprite->setPosition(portraitX,portraitY);
_labelUploadFile->setAlignment(TextHAlignment::LEFT); _labelUploadFile->setAlignment(TextHAlignment::LEFT);
} }
if (playSprite)
{
auto listener = EventListenerTouchOneByOne::create(); auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [](Touch* touch, Event *event)->bool{ listener->onTouchBegan = [](Touch* touch, Event *event)->bool{
auto target = static_cast<Sprite*>(event->getCurrentTarget()); auto target = static_cast<Sprite*>(event->getCurrentTarget());
@ -198,23 +199,16 @@ public:
startScript(""); startScript("");
}; };
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, playSprite); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, playSprite);
}
this->scheduleUpdate(); this->scheduleUpdate();
} }
void playerCallback(Object* sender)
{
startScript("");
}
void update( float fDelta ) void update( float fDelta )
{ {
s_FileNameMutex.lock();
if (s_strFile.length()<1) if (s_strFile.length()<1)
{
return; return;
}
s_FileNameMutex.lock();
_labelUploadFile->setString(s_strFile); _labelUploadFile->setString(s_strFile);
s_FileNameMutex.unlock(); s_FileNameMutex.unlock();
} }