コード例 #1
0
bool Campaign::init()
{
    if ( !SelectSave::init() )
    {
        return false;
    }
    stageNum = stageTag0;
    
    SelectStage *stages = SelectStage::create();
    addChild(stages);
    stages->setTag(campTag_SelectStage);

    
    CCMenuItemFont *start    = CCMenuItemFont::create("START",this,menu_selector(Campaign::menuCloseCallback));
    CCMenuItemFont *soldiers = CCMenuItemFont::create("SOLDIERS",this,menu_selector(Campaign::menuCloseCallback));
    CCMenuItemFont *mainMenu = CCMenuItemFont::create("mainMenu",this,menu_selector(Campaign::menuCloseCallback));
    
    start->setTag(campTag_start);
    soldiers->setTag(campTag_soldiers);
    mainMenu->setTag(campTag_mainMenu);
    
    CCMenu *menu = CCMenu::create(start,soldiers,mainMenu,NULL);
    addChild(menu,10);
    menu->setPosition(CCPointZero);
    menu->alignItemsVertically();
    
    CCSize size = menu->getContentSize();
    CCLOG("%f %f",size.width,size.height);
    menu->setPosition(ccp(size.width/6, size.height/6));
//    menu->setScale(0.5f);
    
    return true;
}
コード例 #2
0
//private
void RPGMapSceneLayer::startPlay(float delay)
{
    CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap);
    
    //数据库部分,读取npc数据
    CppSQLite3Query query = this->m_db.execQuery(CCString::createWithFormat(NPC_QUERY, this->m_mapData.mapId)->getCString());
    while(!query.eof())
    {
        float x = (stringToNumber<float>(query.getStringField("tmx_x")) + 0.5) * GAME_TMX_ROLE_WIDTH;
        float y = (stringToNumber<float>(query.getStringField("tmx_y")) + 0.5) * GAME_TMX_ROLE_HEIGHT;
        bool autoMove = query.getIntField("auto_move") == 1 ? true : false;
        
        RPGMapNPCRoleSprite *npc = RPGMapNPCRoleSprite::create(query.getIntField("id"), CCString::create(query.getStringField("map_texture")), CCString::create("head_texture"), CCString::create(query.getStringField("name_cns")), CCString::create(query.getStringField("content_cns")), 1, autoMove);
        npc->setTag(kRPGMapSceneLayerTagNPC + query.getIntField("id"));
        npc->setPosition(ccp(x, y));
        bgMap->addChild(npc);
        
        query.nextRow();
    }
    query.finalize();
    
    //player
    int defaultSpriteFrameIndex = 1; //默认为向下
    if(this->m_mapData.playerDirection.compare("up") == 0)
    {
        defaultSpriteFrameIndex = 10;
    }
    else if(this->m_mapData.playerDirection.compare("left") == 0)
    {
        defaultSpriteFrameIndex = 4;
    }
    else if(this->m_mapData.playerDirection.compare("right") == 0)
    {
        defaultSpriteFrameIndex = 7;
    }
    RPGMapRoleSprite *player = RPGMapRoleSprite::create(CCString::create("actor4_0.png"), CCString::create("Player"), true, defaultSpriteFrameIndex);
    player->setPosition(ccp(this->m_mapData.playerToX * GAME_TMX_ROLE_WIDTH, this->m_mapData.playerToY * GAME_TMX_ROLE_HEIGHT));
    player->setTag(kRPGMapSceneLayerTagPlayer);
    player->m_type = kRPGMapRoleSpriteTypePlayer;
    bgMap->addChild(player);
    
    CCSprite *spJoystick = CCSprite::createWithSpriteFrameName("Ball.png");
    CCSprite *joystickBg = CCSprite::createWithSpriteFrameName("Dock.png");
    OzgJoystickLayer *joystick = OzgJoystickLayer::layerActivityJoystick(50, spJoystick, joystickBg, false);
    joystick->setTag(kRPGMapSceneLayerTagJoystick);
    joystick->m_target = this;
    joystick->m_endedSelector = callfunc_selector(RPGMapSceneLayer::joystickEndedFunc);
    this->addChild(joystick);
    
    //menu
    CCMenu *mainMenu = CCMenu::create();
    mainMenu->setTag(kRPGMapSceneLayerTagMainMenu);
    mainMenu->setAnchorPoint(ccp(0.5, 0.5));
    mainMenu->setPosition(CCPointZero);
    mainMenu->setContentSize(bgMap->getContentSize());
    bgMap->addChild(mainMenu);

    CCMenuItemSprite *menuCommand = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSceneLayer::onMenu));
    menuCommand->setPosition(ccp(mainMenu->getContentSize().width - 35, mainMenu->getContentSize().height - 35));
    menuCommand->setTag(kRPGMapSceneLayerTagMainMenuCommand);
    menuCommand->setRotation(180);
    menuCommand->setScale(0.75);
    mainMenu->addChild(menuCommand);

//    CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true);
    this->scheduleUpdate();
    
}
コード例 #3
0
ファイル: HelloWorldScene.cpp プロジェクト: joyfish/code
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->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
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));
    
    CCLOG("%.2f,%.2f\n",pMenu->getContentSize().width,pMenu->getContentSize().height);
    

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));


    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    return true;
}