Category: ‘cocos2d-x’

Cocos2d-x 背景画像座標設定の覚え書き

2013年10月20日 Posted by PURGE

典型的な関数に関する覚え書き。

    if ( !CCLayer::init() )
    {
        return false;
    }
    //実際の画面に表示されている領域(width/height)
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    //基本的に0,0(x/y)
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    CCSprite* pBackground = CCSprite::create("Background.png");
    pBackground->setPosition(ccp(origin.x + visibleSize.width/2,
                                 origin.y + visibleSize.height/2));
    
    CCLog("origin.x:%f / orgin.y:%f",origin.x, origin.y);
    CCLog("visibleSize.width:%f / visibleSize.height:%f",visibleSize.width, visibleSize.height);
    CCLog("background.width:%f / background.height:%f",pBackground->getContentSize().width, pBackground->getContentSize().height);
    
    this->addChild(pBackground, 0);

実際試すと、座標設定が理解できるようになる。

Cocos2d-x 縦画面の設定

2013年10月17日 Posted by PURGE

RootViewController.mm

// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //縦画面対応
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    //return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}

// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
    //縦画面対応
    return UIInterfaceOrientationMaskPortrait;
    //return UIInterfaceOrientationMaskAllButUpsideDown;
#endif
}

- (BOOL) shouldAutorotate {
    return NO;
}

Cocos2d-xの画面遷移方法

2013年10月16日 Posted by PURGE

一番簡単な、画面遷移(トランジション付き)の方法の覚え書き。

bool ScreenSample::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    CCMenuItemImage* pNextScreen = CCMenuItemImage::create("Next.png",
                                                           "NextSelected.png",
                                                           this, menu_selector(ScreenSample::nextScreenClicked));
	pNextScreen->setPosition(ccp(origin.x + visibleSize.width - pNextScreen->getContentSize().width/2 ,
                                origin.y + 100));
    
    CCMenu* pNext = CCMenu::create(pNextScreen, NULL);
    pNext->setPosition(CCPointZero);
    this->addChild(pNext, 3);
    
    return true;
}

void ScreenSample::nextScreenBtnClicked(CCObject* pSender)
{
    CCLog("Clicked!!!");
    CCScene* nextScene = NextScreen::scene();
    CCTransitionFlipX* transition = CCTransitionFlipX::create(0.5f, nextScene);
    //CCTransitionFade* transition = CCTransitionFade::create(0.5f, nextScene);
    //CCTransitionZoomFlipY* transition = CCTransitionZoomFlipY::create(0.5f, nextScene);

    CCDirector::sharedDirector()->replaceScene(transition);
}

今後、活用する。

cocos2d-x 事始め

2013年7月18日 Posted by PURGE

はじめて知ったこととして、cocos2d-xプロジェクトを新規作成するには、下記コマンドラインから、pythonコマンドで作成するのも良いらしい。

$ cd /Works/Xcode/cocos2d-x/tools/project-creator 
$ ./create_project.py -project control -package com.whoocus.control -language cpp 
proj.ios		: Done!
proj.android		: Done!
proj.win32		: Done!
proj.mac		: Done!
proj.blackberry		: Done!
proj.linux		: Done!
proj.marmalade		: Done!
New project has been created in this path: /Works/Xcode/cocos2d-x/projects/control
Have Fun!