More Related Content Similar to ㉞cocos2d-xの開発環境をインストールしてみよう (20) More from Nishida Kansuke (20) ㉞cocos2d-xの開発環境をインストールしてみよう16. プロジェクトの作成③
tonosamart-mac-2:project-creator tonosamart$ ./create_project.py project Test -package com.tonosamart.test -language cpp
proj.ios
: Done!
proj.android
: Done!
proj.win32
: Done!
proj.winrt
: Done!
proj.wp8
: Done!
proj.mac
: Done!
proj.blackberry
: Done!
proj.linux
: Done!
proj.marmalade
: Done!
New project has been created in this path: /Users/tonosamart/
cocos/cocos2d-x-2.2/projects/Test
Have Fun!
tonosamart-mac-2:project-creator tonosamart$
40. TitleScene.cpp②
CCSprite* pBgSprite = CCSprite::create("bg.png");
pBgSprite->setPosition(ccp(visibleSize.width/2 + origin.x,
visibleSize.height/2 + origin.y));
this->addChild(pBgSprite, 0);
CCSprite* pChrSprite1 = CCSprite::create("chr.png");
pChrSprite1->setPosition(ccp(0 + origin.x, 0 + origin.y));
this->addChild(pChrSprite1, 1);
CCSprite* pChrSprite2 = CCSprite::create("chr.png");
pChrSprite2->setPosition(ccp(480 + origin.x, 320 + origin.y));
this->addChild(pChrSprite2, 2);
return true;
}
48. AppDelegate.ccp①
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
// ResolutionSize(visibleSize)の設定
// CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
kResolutionExactFit);
// CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
kResolutionNoBorder);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionShowAll);
// CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
kResolutionFixedHeight);
// CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
kResolutionFixedWidth);
// CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
kResolutionUnKnown);
49. AppDelegate.ccp②
// ファイルパスと scale を設定
TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();
CCSize frameSize = CCEGLView::sharedOpenGLView()->getFrameSize();
std::vector<std::string> searchPaths;
searchPaths.push_back("images");
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
std::vector<std::string> resDirOrders;
if (platform == kTargetIphone ¦¦ platform == kTargetIpad){
if (frameSize.height >= 1280){
resDirOrders.push_back("iPad_hd");
pDirector->setContentScaleFactor(4.0f);
}else if (frameSize.height >= 640){
resDirOrders.push_back("iPhone_hd");
pDirector->setContentScaleFactor(2.0f);
}else{
resDirOrders.push_back("iPhone");
}
50. AppDelegate.ccp③
}else{
if (frameSize.height >= 1280){
resDirOrders.push_back("Android_L");
pDirector->setContentScaleFactor(4.0f);
}else if (frameSize.height >= 640){
resDirOrders.push_back("Android_M");
pDirector->setContentScaleFactor(2.0f);
}else{
resDirOrders.push_back("Android_S");
}
}
CCFileUtils::sharedFileUtils()>setSearchResolutionsOrder(resDirOrders);
51. AppDelegate.ccp④
// turn on display FPS
pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
CCScene *pScene = TitleScene::scene();
// run
pDirector->runWithScene(pScene);
return true;
}
53. TitleScene.cpp②
CCString *pLabelTxt = CCString::createWithFormat(
"F(%d,%d) V(%d,%d) O(%d,%d)",
(int)frameSize.width,
(int)frameSize.height,
(int)visibleSize.width,
(int)visibleSize.height,
(int)origin.x,
(int)origin.y
);
CCLabelTTF* pLabel = CCLabelTTF::create(pLabelTxt->getCString() , "Arial", 24);
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + pLabel->getContentSize().height));
this->addChild(pLabel, 1);
54. TitleScene.cpp③
CCSprite* pBgSprite = CCSprite::create("bg.png");
pBgSprite->setPosition(ccp(visibleSize.width/2 + origin.x,
visibleSize.height/2 + origin.y));
this->addChild(pBgSprite, 0);
CCSprite* pChrSprite1 = CCSprite::create("chr.png");
pChrSprite1->setPosition(ccp(0 + origin.x, 0 + origin.y));
this->addChild(pChrSprite1, 1);
CCSprite* pChrSprite2 = CCSprite::create("chr.png");
pChrSprite2->setPosition(ccp(480 + origin.x, 320 + origin.y));
this->addChild(pChrSprite2, 2);
return true;
}