Ejemplo n.º 1
0
bool MainMenuCtrlLayer::init()
{
    bool ret = false;
    
    do {
        CC_BREAK_IF(!CCLayer::init());
        
        CCSize winSize = CCDirector::sharedDirector()->getWinSize();
        
        // 菜单
        // 菜单纹理
        CCImage menuImage;
        menuImage.initWithImageFile("menu.png");
        CCTexture2D *menuTexture = new CCTexture2D();
        menuTexture->initWithImage(&menuImage);
        
        // 菜单选项
        CCMenuItemSprite *newGameMenuItem = CCMenuItemSprite::itemFromNormalSprite(CCSprite::spriteWithTexture(menuTexture, CCRectMake(0, 0, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(0, 33, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(0, 33 * 2, 126, 33)), this, menu_selector(MainMenuCtrlLayer::mainMenuCallback));
        newGameMenuItem->setTag(MAINMENU_ID_NEW_GAME);
        
        CCMenuItemSprite *settingMenuItem = CCMenuItemSprite::itemFromNormalSprite(CCSprite::spriteWithTexture(menuTexture, CCRectMake(126, 0, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(126, 33, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(126, 33 * 2, 126, 33)), this, menu_selector(MainMenuCtrlLayer::mainMenuCallback));
        settingMenuItem->setTag(MAINMENU_ID_SETTING);
        
        CCMenuItemSprite *aboutMenuItem = CCMenuItemSprite::itemFromNormalSprite(CCSprite::spriteWithTexture(menuTexture, CCRectMake(252, 0, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(252, 33, 126, 33)), CCSprite::spriteWithTexture(menuTexture, CCRectMake(252, 33 * 2, 126, 33)), this, menu_selector(MainMenuCtrlLayer::mainMenuCallback));
        aboutMenuItem->setTag(MAINMENU_ID_ABOUT);
        
        CCMenu *mainMenu = CCMenu::menuWithItems(newGameMenuItem, settingMenuItem, aboutMenuItem, NULL);
        mainMenu->alignItemsVerticallyWithPadding(10);
        mainMenu->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 80));
        this->addChild(mainMenu);
        
        ret = true;
    } while (0);
    
    return ret;
}
Ejemplo n.º 2
0
void GameScene::showRateView()
{
    if (m_pRateLayer == NULL)
    {
        m_pRateLayer = LGLayerColor::create(ccc4(0, 0, 0, 0));
        m_pRateLayer->retain();
        m_pRateLayer->setTouchMode(kCCTouchesOneByOne);
        m_pRateLayer->setTouchEnabled(true);
        m_pRateLayer->setZOrder(3);

        CCSprite *pBg = CCSprite::create("rate_bg.png");
        pBg->setPosition(m_VisibleOrigin + m_VisibleSize / 2);
        m_pRateLayer->addChild(pBg);

        float bgW = pBg->getContentSize().width, bgH = pBg->getContentSize().height;
        CCMenuItemImage *pRate = LGMenuItemImage::create("rate_rate.png", NULL, this, menu_selector(GameScene::rateCallback));
        pRate->setPosition(ccp(pBg->getPositionX() - 0.2592593f * bgW, pBg->getPositionY() - 0.6566f * bgH));

        CCMenuItemImage *pLater = LGMenuItemImage::create("rate_later.png", NULL, this, menu_selector(GameScene::laterCallback));
        pLater->setPosition(ccp(pBg->getPositionX() + 0.2592593f * bgW, pRate->getPositionY()));

        CCMenu *pMenu = CCMenu::create(pRate, pLater, NULL);
        pMenu->setAnchorPoint(CCPointZero);
        pMenu->setPosition(CCPointZero);
        m_pRateLayer->addChild(pMenu);
    }

    if (m_pRateLayer && m_pRateLayer->getParent() == NULL)
    {
        getParent()->addChild(m_pRateLayer);
        CC_SAFE_RELEASE_NULL(m_CurrentLayer);
        m_CurrentLayer = m_pRateLayer;
        m_CurrentLayer->retain();
        onShowOverlay(true);
    }
}
void HelloWorld::startGame()
{
    // Initialize arrays
    _targets = new CCArray();
    _projectiles = new CCArray();
    
    // Get the dimensions of the window for calculation purposes
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    player = (Player*)CCSprite::create("Player.png");
    player->setPosition(ccp(player->getContentSize().width/2, winSize.height/2));
    player->isEnemy = false;
    addChild(player);
    
    enemy = (Player*)CCSprite::create("Enemy.png");
    enemy->setPosition(ccp(winSize.width-enemy->getContentSize().width/2, winSize.height/2));
    enemy->isEnemy = true;
    enemy->setOpacity(100);
    addChild(enemy);
    isConnected = true;
    if (isFirstLaunch)
    {
        scheduleUpdate();
    }
    
    CCLabelTTF *buttonTitle = CCLabelTTF::create("Disconnect", "Marker Felt", 30);
    buttonTitle->setColor(ccBLACK);
    
    CCMenuItemLabel *startGameButton = CCMenuItemLabel::create(buttonTitle, this,menu_selector(HelloWorld::disconnect));
    startGameButton->setPosition(ccp(winSize.width/2,winSize.height/4));
    //printf("\nshowStartGameLayer = (%f,%f)",winSize.width/2,winSize.height/2);
    CCMenu *pMenu = CCMenu::create(startGameButton,NULL);
    pMenu->setPosition(CCPointZero);
    this->addChild(pMenu, 1);

}
Ejemplo n.º 4
0
Archivo: Demo.cpp Proyecto: qjsy/QjGit
/*
 *  初始化
 */
bool Demo::init() {
    // super init
    if (!CCLayer::init()) {
        return false;
    }

    CCMenuItemImage *pSellItem = CCMenuItemImage::create( "des.png",
                                                          "des.png",
                                                          this,
                                                          menu_selector(Demo::
                                                            option));
    pSellItem->setAnchorPoint(ccp(0, 0));
    pSellItem->setPosition(ccp(0, 0));
    CCMenu* menu = CCMenu::create(pSellItem, NULL);
    menu->setAnchorPoint(ccp(0, 0));
    menu->setPosition(ccp(0, 0));
    addChild(menu);
    
    CCSprite* sp = CCSprite::create("desfont.png");
    sp->setAnchorPoint(ccp(0.5, 0));
    sp->setPosition(ccp(320, 50));
    addChild(sp);
    CCActionInterval * scale = CCScaleTo::create(1, 1.1);
    CCActionInterval * scale1 = CCScaleTo::create(1.5, 1);
    CCFiniteTimeAction * seq= CCSequence::create(scale, scale1, NULL);
    CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq);
    sp->runAction(repeatForever);
    
    /**/
    LoginLayer* login = LoginLayer::create();
    login->setVisible(false);
    login->setTouchEnabled(false);
    this->addChild(login, 1, 100);

    return true;
}
Ejemplo n.º 5
0
bool Bug1159Layer::init()
{
    if (BugsTestBaseLayer::init())
	{
        CCSize s = CCDirector::sharedDirector()->getWinSize();

        CCLayerColor *background = CCLayerColor::layerWithColor(ccc4f(255, 0, 255, 255));
		addChild(background);

        CCLayerColor *sprite_a = CCLayerColor::layerWithColorWidthHeight(ccc4f(255, 0, 0, 255), 700, 700);
		sprite_a->setAnchorPoint(ccp(0.5f, 0.5f));
		sprite_a->setIsRelativeAnchorPoint(true);
		sprite_a->setPosition(ccp(0.0f, s.height/2));
		addChild(sprite_a);

        sprite_a->runAction(CCRepeatForever::actionWithAction((CCActionInterval*) CCSequence::actions(
                                                               CCMoveTo::actionWithDuration(1.0f, ccp(1024.0f, 384.0f)),
                                                               CCMoveTo::actionWithDuration(1.0f, ccp(0.0f, 384.0f)),
															   NULL)));

        CCLayerColor *sprite_b = CCLayerColor::layerWithColorWidthHeight(ccc4f(0, 0, 255, 255), 400, 400);
		sprite_b->setAnchorPoint(ccp(0.5f, 0.5f));
		sprite_b->setIsRelativeAnchorPoint(true);
		sprite_b->setPosition(ccp(s.width/2, s.height/2));
		addChild(sprite_b);

        CCMenuItemLabel *label = CCMenuItemLabel::itemWithLabel(CCLabelTTF::labelWithString("Flip Me", "Helvetica", 24), this, menu_selector(Bug1159Layer::callBack));
        CCMenu *menu = CCMenu::menuWithItems(label, NULL);
		menu->setPosition(ccp(s.width - 200.0f, 50.0f));
		addChild(menu);

        return true;
	}

	return false;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    CCNode *pFishJoyScene = SceneReader::sharedSceneReader()->createNodeWithSceneFile("FishJoy2.json");
	this->addChild(pFishJoyScene);
    cocos2d::extension::ActionManager::shareManager()->playActionByName("startMenu_1.json","Animation1");

	CCMenuItemFont *itemBack = CCMenuItemFont::create("End", this, menu_selector(HelloWorld::menuCloseCallback));
    itemBack->setColor(ccc3(255, 255, 255));
    itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
    CCMenu *menuBack = CCMenu::create(itemBack, NULL);
    menuBack->setPosition(CCPointZero);
    menuBack->setZOrder(4);
    
    this->addChild(menuBack);

    return true;
}
GetPeanuts::GetPeanuts()
{
        // enable touches
    setTouchEnabled( true );
    
    float scale = ScreenHelper::getTextureScale();
    float scaleX = ScreenHelper::getTextureScaleX();
    float scaleY = ScreenHelper::getTextureScaleY();
		
    
    CCSprite *spriteReturn = CCSprite::createWithSpriteFrameName("ctm_Store_Shopping_Btn.png");
    CCSprite *spriteReturnDown = CCSprite::createWithSpriteFrameName("ctm_Store_Shopping_Btn_Down.png");
    
    CCMenuItem *returnButton = CCMenuItemSprite::create(spriteReturn,spriteReturnDown,this,menu_selector(GetPeanuts::returnButtonTapped));
    returnButton->setScale(scale);
    returnButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,90.0f,130.0f));
    
    CCMenu* backmenu = CCMenu::create(returnButton, NULL);
    backmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT));
    addChild(backmenu,4);
    
    setPosition(CCPointMake(-480*scaleX, 0));
    runAction(CCMoveBy::create(0.15f,CCPointMake(480*scaleX, 0)));
        
    bMenuBuilt = false;
    isReturning = false;
        
    if(SaveLoad::m_SaveData.beenToPeanuts==0)
    {
        SaveLoad::m_SaveData.beenToPeanuts=1;
        SaveLoad::Save();
        // [TestFlight passCheckpoint:@"PEANUT_VISIT"];
    }

    scheduleUpdate();
}
Ejemplo n.º 8
0
void EaseSpriteDemo::onEnter()
{
	CCLayer::onEnter();

	// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
    m_grossini = CCSprite::spriteWithFile(s_pPathGrossini); m_grossini->retain();
	m_tamara = CCSprite::spriteWithFile(s_pPathSister1); m_tamara->retain();
	m_kathia = CCSprite::spriteWithFile(s_pPathSister2); m_kathia->retain();
	
	addChild( m_grossini, 3);
	addChild( m_kathia, 2);
	addChild( m_tamara, 1);

	CCSize s = CCDirector::sharedDirector()->getWinSize();

	m_grossini->setPosition( CCPointMake(60, 50) );
	m_kathia->setPosition( CCPointMake(60, 150) );
	m_tamara->setPosition( CCPointMake(60, 250) );

	CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
	addChild(label);
	label->setPosition( CCPointMake(s.width/2, s.height-50) );

	CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(EaseSpriteDemo::backCallback) );
	CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(EaseSpriteDemo::restartCallback) );
	CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(EaseSpriteDemo::nextCallback) );

	CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);

	menu->setPosition( CCPointZero );
	item1->setPosition( CCPointMake( s.width/2 - 100,30) );
	item2->setPosition( CCPointMake( s.width/2, 30) );
	item3->setPosition( CCPointMake( s.width/2 + 100,30) );
	
	addChild(menu, 1);	
}
Ejemplo n.º 9
0
void CMemberListPopLayer::onEnter()
{
	CPopLayerBase::onEnter();

	Node *parent = getChildByTag( E_Tag_Bg );
	if( !parent )
	{
		CCLog( "[CMemberListPopLayer::onEnter] get parent null" );
		return;
	}
	CCMyMenuItemImage *closeItem = CCMyMenuItemImage::create(
		"close_normal.png",
		"close_hover.png",
		this,
		menu_selector(CMemberListPopLayer::menuCloseCallback) );
	if( !closeItem )
	{
		CCLog( "[CMemberListPopLayer::onEnter] close item null" );
		return;
	}
	Size szItem = closeItem->getContentSize();
	Size szParent = parent->getContentSize();
	closeItem->setAnchorPoint( ccp(0.5, 0.5) );
	closeItem->setPosition( ccp( szParent.width-szItem.width, szParent.height-szItem.height ) );

	CCMenu *menu = CCMenu::create( closeItem, NULL );
	if( !menu )
	{
		CCLog( "[CMemberListPopLayer::onEnter] close menu null" );
		return;
	}
	menu->setPosition( CCPointZero );
	parent->addChild( menu, 1 );

	_AddMemberList();
}
Ejemplo n.º 10
0
bool HelpLayer::init()
{
	if (!CCLayer::init())  
    {  
        return false;  
    }
      
    CCSize s = CCDirector::sharedDirector()->getWinSize();

	//bg
	CCSprite* bg = CCSprite::create(PIC_MAIN_BACKGROUND);
	bg->setAnchorPoint(ccp(0,0));
	addChild(bg);

	//text
	CCLabelTTF* text = CCLabelTTF::create(a2u(s_helpText).c_str(), "Arial", 40.0f, CCSizeMake(500,700), kCCTextAlignmentLeft);
	text->setPosition(ccp(s.width*0.5, s.height*0.5));
	addChild(text);	
	
	text = CCLabelTTF::create(a2u("北京天普教育").c_str(), "Arial", 30.0f);
	text->setPosition(ccp(450, 250));
	addChild(text);	

	//quit menu
	CCMenuItemImage* quit = CCMenuItemImage::create(
            PIC_BUTTON_BACK,
            PIC_BUTTON_BACK_SELECTED,
            this,
            menu_selector(HelpLayer::quit));
	CCMenu* menu = CCMenu::create(quit, NULL);
	menu->setPosition(ccp(s.width*0.5, 120));
	this->addChild(menu);

	return true;

}
Ejemplo n.º 11
0
void RS_Main::onEnter()
{
    setKeypadEnabled(true);

    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->addTargetedDelegate((CCTargetedTouchDelegate *)this, 1, true);
    CCLayerColor::onEnter();

    char* szLang = LanguageUtil::getLanguageCode();
    // 수학/과학 동화 미션 수행일 경우 안내 문구 출력
    if(PROJECT_TYPE == TYPE_EDUNATION)
    {
        char szInfo[260];
        sprintf(szInfo, "eBook/%02d/rememberStory/info_rs_%s.png", m_nCurEBookPage, szLang);

        m_pInfoItem = CCMenuItemImage::create(szInfo, szInfo, this, menu_selector(RS_Main::menuClickCallback));
        m_pInfoItem->setTag(4);

        CCMenu* pInfo = CCMenu::create();
        pInfo->addChild(m_pInfoItem);
        pInfo->setPosition(ccp(s.width/2, s.height/2));
        this->addChild(pInfo, 200);

        // 미션으로 화면 전환시 이전화면과 구분을 위한 화면 전환 시간동안 표시할 하단 바 생성
        m_pBottomBar = CCSprite::create("common/game/mission_bottom.png");
        m_pBottomBar->setPosition(ccp(s.width/2, m_pBottomBar->getContentSize().height/2));
        addChild(m_pBottomBar, 1000);
        scheduleOnce(schedule_selector(RS_Main::invisibleBottomBar), 1.0f);
    }

    // Mission Played flag 설정
    char cMissionPlayed[30];
    sprintf(cMissionPlayed, "mission_played_%d_%s", m_nCurEBookPage, szLang);
    CCUserDefault::sharedUserDefault()->setBoolForKey(cMissionPlayed, true);
    CCUserDefault::sharedUserDefault()->flush();
}
Ejemplo n.º 12
0
bool UserInputScene::init()
{
	if (!CCLayer::init())
	{
		return false;
	}


	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

	CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile("welcome.plist","welcome.png");


	CCSprite* bgSprite = CCSprite::create("login_2.png");
	bgSprite->setAnchorPoint(CCPointZero);
	bgSprite->setPosition(ccp(origin.x,origin.y));
	this->addChild(bgSprite,9);


	CCSprite* buttonSprite = CCSprite::create("start.png");
	//buttonSprite->setAnchorPoint(CCPointZero);
	//buttonSprite->setScale(0.5f);
	//buttonSprite->setPosition(ccp(origin.x+visibleSize.width/2,origin.y));
	//this->addChild(buttonSprite);

	SEL_MenuHandler startSelect= (SEL_MenuHandler)menu_selector(UserInputScene::startGame);
	CCMenuItemSprite* startMenu = CCMenuItemSprite::create(buttonSprite,
		buttonSprite, buttonSprite, this,
		startSelect );
	CCMenu* menu = CCMenu::create(startMenu,NULL);
	menu->setPosition(ccp(origin.x+visibleSize.width/2,origin.y));
	menu->setScale(0.5f);
	addChild(menu,10);



	CCSize editBoxSize = CCSizeMake(visibleSize.width - 100, 60);

	// top
	m_pEditName = CCEditBox::create(editBoxSize, CCScale9Sprite::create("username.png"));
	m_pEditName->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height*3/4));
	m_pEditName->setFontSize(25);
	m_pEditName->setFontColor(ccRED);
	m_pEditName->setPlaceHolder("Name:");
	m_pEditName->setPlaceholderFontColor(ccWHITE);
	m_pEditName->setMaxLength(8);
	m_pEditName->setReturnType(kKeyboardReturnTypeDone);
	m_pEditName->setDelegate(this);
	addChild(m_pEditName,10);

	m_pEditPassword = CCEditBox::create(editBoxSize, CCScale9Sprite::create("username.png"));
	m_pEditPassword->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));
	m_pEditPassword->setFontColor(ccGREEN);
	m_pEditPassword->setPlaceHolder("Password:"******"SelectSong1_1.json"));
	//ul->addWidget(widget);

	//Button* startBT = (Button*)ul->getWidgetByName("Button_28");
	//startBT->addTouchEventListener(this,toucheventselector(UserInputScene::startGame));
	//////////////////////////////////////////////////////////////////////////
	return true;
}
Ejemplo n.º 13
0
// on "init" you need to initialize your instance
bool ControlLayer::init()
{

    // 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

    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png",
                                        this,
                                        menu_selector(ControlLayer::menuCloseCallback) );
    pCloseItem->setPosition( ccp(winSize.width-20, 20) );
    pCloseItem->setScale(0.5);
    pCloseItem->setOpacity(200);

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

    CCMenuItemImage *upItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Moveup));
    CCMenuItemImage *downItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Movedown));
    CCMenuItemImage *rightItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Moveright));
    CCMenuItemImage *leftItem = CCMenuItemImage::create("button.png", "selected.png", this, menu_selector(ControlLayer::Moveleft));

    int bX; //the x coordination
    int bY; //the y coordination

    int sizeAdjustionRatioConstant = 3;    // for the auto adjusting size
    float bScale = winSize.height / (sizeAdjustionRatioConstant * 100); // (screenHeight / buttonHeight) * ratioConstant
    int transparence = 30;

    bX = (winSize.width / 2);
    bY = (winSize.height / 6) * 5;
    upItem->setPosition( ccp(bX, bY) );
    upItem->setOpacity(transparence);
    upItem->setScale(bScale);


    bX = (winSize.width / 2);
    bY = (winSize.height / 6) * 1;
    downItem->setPosition( ccp(bX, bY) );
    downItem->setOpacity(transparence);
    downItem->setRotation(180);
    downItem->setScale(bScale);

    bX = (winSize.width / 6) * 5;
    bY = (winSize.height / 2);
    rightItem->setPosition( ccp(bX, bY) );
    rightItem->setOpacity(transparence);
    rightItem->setRotation(90);
    rightItem->setScale(bScale);

    bX = (winSize.width / 6) * 1;
    bY = (winSize.height / 2);
    leftItem->setPosition( ccp(bX, bY) );
    leftItem->setOpacity(transparence);
    leftItem->setRotation(270);
    leftItem->setScale(bScale);


    CCMenu* moveItem = CCMenu::create(upItem, downItem, rightItem, leftItem, NULL);
    moveItem->setPosition( CCPointZero );
    this->addChild(moveItem, 0);


    return true;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    /////////////////////////////
    // 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(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );

    // 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("Cocos2dx GreePlatform Binding Test", "Thonburi", 34);

    // ask director the window size
    CCSize size = CCDirector::sharedDirector()->getWinSize();

    // position the label on the center of the screen
    pLabel->setPosition( ccp(size.width / 2, size.height - 20) );

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

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

    // position the sprite on the center of the screen
    pSprite->setPosition( ccp(size.width/2, size.height/2) );

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

	// GreeButton
	pGreeButtonText = CCLabelTTF::create("Log in", "Thonburi", 34);
	pGreeButtonText->setPosition(ccp(size.width - 100, size.height - 40));
	this->addChild(pGreeButtonText, 1);
	CCMenuItemImage *pGree = CCMenuItemImage::create("gree.png", "gree.png", this, menu_selector(HelloWorld::menuGreeButtonCallback));
	pGree->setPosition(ccp(size.width - 100, size.height - 100));
	CCMenu* pGreeMenu = CCMenu::create(pGree, NULL);
	this->addChild(pGreeMenu, 1);
	pGreeMenu->setPosition(CCPointZero);
	pGree->setScaleY(3.0);
	pGree->setScaleX(3.0);		

    return true;
}
Ejemplo n.º 15
0
bool OptionLayer::init()
{
     if ( !CCLayer::init() )
    {
        return false;
    }

    // add options splash screen
    CCSprite* pSprite = CCSprite::create("options_screen.jpg");

    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

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

    pSprite->setScaleY(visibleSize.height/pSprite->getContentSize().height);
    // add the sprite as a child to this layer
    this->addChild(pSprite);

    //create option button
    CCSprite *on= CCSprite::create("soundOn.png");

    //create start button
    CCSprite *off = CCSprite::create("soundOff.png");

    //create the two items
    CCMenuItemSprite *OnItem = CCMenuItemSprite::create(on, on, this, menu_selector(OptionLayer::turnSoundOn));
    if(!OnItem) return false;
    CCMenuItemSprite *OffItem = CCMenuItemSprite::create(off, off, this, menu_selector(OptionLayer::turnSoundOff));
    if(!OffItem) return false;


    //create menu
    CCMenu* pMenu = CCMenu::create(OnItem, NULL);
    if(!pMenu) return false;

    CCMenu* pMenu2 = CCMenu::create(OffItem, NULL);
    if(!pMenu2) return false;

    //setup positioning
    pMenu->setPosition(ccp(visibleSize.width/5.0, visibleSize.height/6.0));
    //OptionItem->setPosition(ccp(visibleSize.width/4.0, visibleSize.height/6.0));
    pMenu2->setPosition(ccp(visibleSize.width/2.0, visibleSize.height/6.0));
    //StartItem->setPosition(ccp(visibleSize.width/3.0, visibleSize.height/4.0));

    //pMenu->alignItemsHorizontallyWithPadding(300.0f);

    //add menu item as layer
    this->addChild(pMenu, 1);
    this->addChild(pMenu2, 1);

    volume1 = CocosDenshion::SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume();
    volume2 = CocosDenshion::SimpleAudioEngine::sharedEngine()->getEffectsVolume();

    // Create a back button
    CCMenuItemImage *pCloseItem = CCMenuItemImage::create("back-button.png", "back-button.png", this, menu_selector(OptionLayer::BacktoMain));
        
    // Place the menu item bottom-right conner.
    pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
                                origin.y + pCloseItem->getContentSize().height/2));

    // Create a menu with the "close" menu item, it's an auto release object.
    CCMenu* pMenu3 = CCMenu::create(pCloseItem, NULL);
    pMenu3->setPosition(CCPointZero);

    // Add the menu to Option layer as a child layer.
    this->addChild(pMenu3, 1);

    return true;

}
Ejemplo n.º 16
0
// 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", TITLE_FONT_SIZE);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->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);
    
//    CCClippingNode * clippingNodeLeft = CCClippingNode::create();
//    addChild(clippingNodeLeft);
//    clippingNodeLeft->addChild(pSprite,0);
//    CCDrawNode *shapeLeft = CCDrawNode::create();
//    static CCPoint triangleLeft[3];
//    triangleLeft[0] = ccp(0, 0);
//    triangleLeft[1] = ccp(visibleSize.width,0);
//    triangleLeft[2] = ccp(0,visibleSize.height);
//    static ccColor4F green = {0, 1, 0, 1};
//    shapeLeft->drawPolygon(triangleLeft, 3, green, 0, green);
//    clippingNodeLeft->setStencil(shapeLeft);
//    clippingNodeLeft->setInverted(false);
    
    return true;
}
Ejemplo n.º 17
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());

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

        // 1. Add a menu item with "X" image, which is clicked to quit the program.

        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",
            "CloseSelected.png",
            this,
            menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);

        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);

        // 2. Add a label shows "Hello World".

        // Create a label and initialize with string "Hello World".
        CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
        CC_BREAK_IF(! pLabel);

        // Get window size and place the label upper. 
        CCSize size = CCDirector::sharedDirector()->getWinSize();
        pLabel->setPosition(ccp(size.width / 2, size.height - 50));

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

        // 3. Add add a splash screen, show the cocos2d splash image.
        CCSprite* pSprite = CCSprite::create("HelloWorld.png");
        CC_BREAK_IF(! pSprite);

        // Place the sprite on the center of the screen
        pSprite->setPosition(ccp(size.width/2, size.height/2));

        // Add the sprite to HelloWorld layer as a child layer.
        this->addChild(pSprite, 0);

         bRet = true;

		shareCamera->setSceneSize(size.width,size.height);
		this->addChild((CCNode*)(shareCamera->getGUI()));
	
		IrrButton* button = IrrButton::create("CloseNormal.png","CloseSelected.png",false);
		button->setPosition(300,100);
		button->addClickEvent(this,irr_gui_clickselector(HelloWorld::onClickHandler));
	//	shareCamera->appendToGUI(button);
		std::string name = "btn 0";
		button->setName(name);



		IrrButton* button1 = IrrButton::create("CloseNormal.png","CloseSelected.png",false);
		button1->addClickEvent(this,irr_gui_clickselector(HelloWorld::onClickHandler));
		std::string name1 = "btn 1";
		button1->setName(name1);
		button1->setPosition(300,310);
		shareCamera->appendToGUI(button1);

		IrrButton* button2 = IrrButton::create("CloseNormal.png","CloseSelected.png",false);
		button2->addClickEvent(this,irr_gui_clickselector(HelloWorld::onClickHandler));
		std::string name2 = "btn 2";
		button2->setName(name2);
		button2->setPosition(20,0);
		button1->addWidget(button2);

		IrrButton* button3= IrrButton::create("CloseNormal.png","CloseSelected.png",false);
		button3->addClickEvent(this,irr_gui_clickselector(HelloWorld::onClickHandler));
		std::string name3 = "btn 3";
		button3->setName(name3);
		button3->setPosition(310,310);
		shareCamera->appendToGUI(button3);

		for (int i = 5; i < 500;i++)
		{
// 			button3= IrrButton::create("CloseNormal.png","CloseSelected.png",false);
// 			button3->addClickEvent(this,irr_gui_clickselector(HelloWorld::onClickHandler));
// 			name3 = "btn";
// 			name3 += irr_utils::IrrStringUtils::IntToString(i);
// 			button3->setName(name3);
// 			int  x = irr_utils::IrrMathUtils::RandomInt(960);
// 			int  y = irr_utils::IrrMathUtils::RandomInt(640);
// 			button3->setPosition(x,y);
// 			shareCamera->appendToGUI(button3);
		}
		//shareCamera->appendToGUI(button2);
// 		IrrPngLabel* pPngLabel = IrrPngLabel::create("123123sfdgfgsf2");
// 		pPngLabel->setPosition(300,300);
// 		pPngLabel->setDimensions(30,300);
// 
// 		//pPngLabel->setFontSize(18);
// 		//pPngLabel->setVerticalTextAlign(kCCVerticalTextAlignmentBottom);
// 		pPngLabel->setTextAlign(kCCTextAlignmentCenter);
// 		pPngLabel->setTouchable(true);
// 		shareCamera->appendToGUI(pPngLabel);
		
		//pPngLabel->setDimensions(300,200);

		IrrTextFieldTTF* pLabelTTF = IrrTextFieldTTF::create();
		pLabelTTF->setString("123123123123123sfds");
		shareCamera->appendToGUI(pLabelTTF);
		pLabelTTF->setPosition(200,200);

		CCNode* pChild1 = CCNode::create();
		CCNode* pChild2 = CCNode::create();
		this->addChild(pChild1);
		this->addChild(pChild2);

    } while (0);

    return bRet;
}
Ejemplo n.º 18
0
bool MenuLayerPlayerSelect::init()
{
	if (CCLayerColor::initWithColor(ccc4(0,0,0,0)))
	{
		

		/*CCSprite* sprite1=CCSprite::create("HelloWorld.png");
		addChild(sprite1);
		sprite1->setPosition(ccp(s.width/2,s.height/2));*/

		//左右滑屏箭头改用菜单比较好。方便回调
		/*CCSprite* leftarrow=CCSprite::create("images/b2.png");
		CCSprite* rightarrow=CCSprite::create("images/f2.png");

		addChild(leftarrow);
		addChild(rightarrow);

		leftarrow->setPosition(ccp(20+leftarrow->getContentSize().width/2,s.height/2));
		rightarrow->setPosition(ccp(s.width-20-rightarrow->getContentSize().width/2,s.height/2));
		*/

		/*飞机精灵用plist实现
		CCSprite* play1=CCSprite::create("images/pea.png");
		CCSprite* play2=CCSprite::create("	");
		addChild(play1);
		addChild(play2);
		play1->setPosition(ccp(s.width/2-100,s.height/2));
		play2->setPosition(ccp(s.width/2+100,s.height/2));
		*/


		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Monster.plist","Monster.png");


		pHero1=CCSprite::createWithSpriteFrameName("Monster1.png");
		pHero1->setPosition(ccp(s.width/2,s.height/2));
		//pHero1->setScale(1.5f);
		pHero1->setRotation(180);
		this->addChild(pHero1);

		pHero6=CCSprite::createWithSpriteFrameName("Monster6.png");
		pHero6->setPosition(ccp(s.width+pHero6->getContentSize().width,s.height/2));
		//pHero6->setScale(1.5f);
		pHero6->setRotation(180);
		this->addChild(pHero6);

		CCMenuItemImage *pLeftItem = CCMenuItemImage::create("images/b2.png","images/b1.png",this,	menu_selector(MenuLayerPlayerSelect::MenuLeftSlideCallBack) );
		pLeftItem->setPosition(ccp(20+pLeftItem->getContentSize().width/2,s.height/2));

		CCMenuItemImage *pRightItem = CCMenuItemImage::create("images/f2.png","images/f1.png",this,	menu_selector(MenuLayerPlayerSelect::MenuRightSlideCallBack) );
		pRightItem->setPosition(ccp(s.width-20-pRightItem->getContentSize().width/2,s.height/2));
		
		CCLabelBMFont* label_start=CCLabelBMFont::create("Start","fonts/bitmapFontTest3.fnt");
		CCMenuItemLabel* item_start=CCMenuItemLabel::create(label_start,this,menu_selector(MenuLayerPlayerSelect::MenuStartGameCallBack));
		item_start->setPosition(s.width/2,pRightItem->getPositionY()-80);

		//CCMenuItemSprite* phero1_item=CCMenuItemSprite::create(pHero1,pHero1,this,menu_selector(MenuLayerPlayerSelect::MenuHeroSelectedCallBack));

		CCMenu* menu=CCMenu::create(pLeftItem,pRightItem,item_start,NULL);

	

		this->addChild(menu);
		menu->setPosition(CCPointZero);

		/*CCSprite* sp_return=CCSprite::create("images/r1.png");
		
		addChild(sp_return);
		
		sp_return->setPosition(ccp(s.width-sp_return->getContentSize().width/2-20,sp_return->getContentSize().height/2+20));*/
		//返回主界面菜单
		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
		CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

		CCMenuItemImage *item_home = CCMenuItemImage::create("images/r1.png","images/r2.png",	this,menu_selector(MenuLayerPlayerSelect::menuGoHomeCallback));

		item_home->setPosition(ccp(origin.x + visibleSize.width - item_home->getContentSize().width/2 ,	origin.y + item_home->getContentSize().height/2));

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

		this->setTouchEnabled(true);
		
		return true;
	}
	return false;

}
Ejemplo n.º 19
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();
    
}
Ejemplo n.º 20
0
QuestionMark::QuestionMark()
{
    setTouchEnabled( true );

    float scale = ScreenHelper::getTextureScale();
    float scaleX = ScreenHelper::getTextureScaleX();
    float scaleY = ScreenHelper::getTextureScaleY();
    
    CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist");
    
    CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist");
    
    CCSprite *sprite = CCSprite::create("MainBackFiller.png");
    sprite->setScaleX(scaleX*1.2f);
    sprite->setScaleY(scaleY*1.2f);
    sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f));
    addChild(sprite);
    
    sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png");
    sprite->setScaleX(scaleX);
    sprite->setScaleY(scaleY);
    sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER));
    addChild(sprite,2);
    
    CCLabelTTF *label = CCLabelTTF::create("?", "impact.ttf", 42*scale);
    addChild(label, 2);
    label->setColor(ccc3(0,0,0));
    label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f));
    
    label = CCLabelTTF::create("?", "impact.ttf", 42*scale);
    addChild(label, 2);
    label->setColor(ccc3(237,188,0));
    label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f));
    
    CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(QuestionMark::backButtonTapped));
    BackButton->setScale(scale);
    BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f));
    
    CCMenu* menu = CCMenu::create(BackButton, NULL);
    menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT));
    addChild(menu,4);
    
    CCSize dim;
    int randInt = RandomInt(0,100);
    if(randInt>95)
    {
        dim.width = 420*scale;
        dim.height = 250*scale;
        const char *colorText = "\"Surely you can't be serious!\" he says, as he slowly ambles back to his crimson hued overstuffed chair.  You find yourself contemplating the simian who rebuffed your overture so out of hand.  You can't help but admire this modern Grigori Rasputin for his steely determination.  With perhaps undue influence of aqua vitae and plantains coloring your reason, you counter with tremendous vigor.  With all the potency of Hannibal and his terrene leviathan you fill your hands with your own ordure and volley it squarely into his agape maw.";
        
        CCLabelTTF *text = CCLabelTTF::create(colorText,"impact.ttf",16*scale,dim,kCCTextAlignmentCenter);
        text->setColor(ccc3(230,230,230));
        text->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0.0f, -70.0f));
        addChild(text);
    }
    else if(randInt>5)
    {
        int randomImage = RandomInt(1,14);
        
        CCTextureCache::sharedTextureCache()->addPVRImage("QuestionMark.pvr.ccz");
        CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("QuestionMark.plist");
        
        char temp[64];
        sprintf(temp,"ConceptArt_%02d.png",randomImage);
        CCSprite *image = CCSprite::createWithSpriteFrameName(temp);
        image->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0.0f, -35.0f));
        image->setScale(0.5f*scale);
        addChild(image);
    }
    else
    {
        dim.width = 420*scale;
        dim.height = 250*scale;
        const char *colorText = "?";
        
        CCLabelTTF *text = CCLabelTTF::create(colorText,"impact.ttf",80*scale,dim,kCCTextAlignmentCenter);
        text->setColor(ccc3(230,230,230));
        text->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0.0f, -70.0f));
        addChild(text);
    }
}
Ejemplo n.º 21
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if ( !CCLayer::init() )
	{
		return false;
	}

    //initPhysic();
    //addPhysicSprite();

    _inputGrid = NULL;

    //此处开启单点触摸,需要重写ccTouchBegan,ccTouchEnded
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,true); 
    //此处开启多点触摸
    //this->setTouchEnabled(true);

	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

    //g_logger->Log(WStrToUTF8(L"你好").c_str());

	/////////////////////////////
	// 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(
										s_BtnCloseNormal,
										s_BtnCloseSelected,
										this,
										menu_selector(HelloWorld::menuCloseCallback));
	
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
								origin.y + pCloseItem->getContentSize().height/2));

    CCMenuItemFont *pMenuItem = CCMenuItemFont::create("Main",this,menu_selector(HelloWorld::menuGotoMainMenu));
    pMenuItem->setFontSize(10);
    pMenuItem->setColor(ccc3(0,0,0));
    pMenuItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
								origin.y + pCloseItem->getContentSize().height/2+30));
	// create menu, it's an autorelease object
	CCMenu* pMenu = CCMenu::create(pCloseItem,pMenuItem, NULL);
	pMenu->setPosition(CCPointZero);
	this->addChild(pMenu, 1);

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

	_background = CCSprite::create(s_BackGround);
    _background->setVisible(true);

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

	// add the sprite as a child to this layer
	this->addChild(_background, Z_BACKGROUND);

	_background->setScale(1.0);

	int i = 0;
	CCTexture2D* gridTexture = CCTextureCache::sharedTextureCache()->addImage(s_Grid);
	g_gridSize = gridTexture->getContentSize();

    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile("Images/ccbDefaultImages.plist");

    CCLOG("grid size width:%0.1f,height:%0.1f",g_gridSize.width,g_gridSize.height);
    CCPoint gridOrigin(ccp(O_GRID_X,O_GRID_Y));
    
    g_pad = InputPad::create();
    g_pad->setAnchorPoint(ccp(0,0));
    g_pad->setVisible(false);
    g_pad->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
	this->addChild(g_pad,Z_INPUTPAD);

    CCLOG("g_pad width:%0.1f,height:%0.1f",g_pad->getContentSize().width,g_pad->getContentSize().height);

    XAXA::LevelMap* level_map = XAXA::LevelMgr::instance()->get_level_map(XAXA::LevelMgr::instance()->get_curr_level());
    XAXA::SudokuLevelMap* sudoku = dynamic_cast<XAXA::SudokuLevelMap*>(level_map);
    int* level = sudoku->get_level();
	for(i=0;i<SUDOKU_GRID;i++) {
		for(int j=0;j<SUDOKU_GRID;j++) {
			bool isStatic = (level[i*SUDOKU_GRID+j] !=255);
			Grid* pGrid = Grid::GridWithTexture(gridTexture,level[i*SUDOKU_GRID+j],isStatic);
			pGrid->GetNode()->setPosition(ccp(gridOrigin.x+j*(g_gridSize.width+2),
				gridOrigin.y+(i+1)*(g_gridSize.height+2)));
			this->addChild(pGrid->GetNode(), Z_GRID_NUMBER);
            g_GridList[i*SUDOKU_GRID+j] = pGrid;
		}
	}
	return true;
}
Ejemplo n.º 22
0
void SGFirstSubLayer::constructView()
{
    //在firstLayer中添加资源
    CCSprite *bg = CCSprite::createWithSpriteFrameName("embattle_huilan_lan.png");
    this->addChild(bg,-10);
    bg->setPosition(ccp(_viewSize.width/2, _viewSize.height/2));
    
    CCString *headString = NULL;
    CCString *countryStr = NULL;
    
    
    if (enterType == 0 ||enterType == 1 )
    {
        if(!_officerCard)
        {
			SGButton *spriteButton = SGButton::create("embattle_font_kong_lan.png", NULL, this, menu_selector(SGFirstSubLayer::selectEmbattle),CCPointZero,false,true);

			CCMenu *menu2 = CCMenu::create(spriteButton, NULL);
			this->addChild(menu2, 0, 125);
			menu2->setPosition(ccp(_viewSize.width/2, _viewSize.height/2));
        }
        else
        {
            CCString *string = CCString::createWithFormat("head%d.png",_officerCard->getHeadSuffixNum());//12.05
            headString = CCString::create(string->getCString());
            SGMainManager::shareMain()->addHeadIconPlistByNum(_officerCard->getHeadSuffixNum(), sg_firstLayer);//12.05

            SGOfficerDataModel *temp = SGStaticDataManager::shareStatic()->getOfficerById(_officerCard->getItemId());
            int starlvl = temp->getOfficerCurrStarLevel();
            if (starlvl>1)
            {
                starlvl-=1;
            }
            countryStr = CCString::createWithFormat("officerPinzhi_%d_0.png",starlvl);
            CCSprite *spriteFont = CCSprite::createWithSpriteFrameName(countryStr->getCString());
            spriteFont->setPosition(ccp(_viewSize.width/2, _viewSize.height/2));
            
            spriteFont->removeChildByTag(30);
            CCSprite *countryName = CCSprite::createWithSpriteFrameName((CCString::createWithFormat("countryName%d.png",temp->getOfficerRace()))->getCString());
            countryName->setAnchorPoint(ccp(1,1));
            countryName->ignoreAnchorPointForPosition(false);
            countryName->setPosition(ccp(spriteFont->getContentSize().width*.36 - countryName->getContentSize().width,spriteFont->getContentSize().height - countryName->getContentSize().height * 2));
            countryName->setVisible(false);    //cgpRemove
            
            //spriteFont->addChild(countryName,30,30);
            
            
            SGCCLabelTTF *lvl = SGCCLabelTTF::create(CCString::createWithFormat("Lv%d",_officerCard->getCurrLevel())->getCString(), FONT_PANGWA, 23);
            this->addChild(lvl,22);
            lvl->setAnchorPoint(ccp(0.5, 0));
            lvl->setPosition(ccpAdd(spriteFont->getPosition(), ccp(0, -spriteFont->getContentSize().height*.35 -10)));

            int id = SGTeamgroup::shareTeamgroupInfo()->getiscurrent();
            if (SGTeamgroup::shareTeamgroupInfo()->islord(id,_officerCard))
            {
                CCSprite *lord = CCSprite::createWithSpriteFrameName("font_zj_bg.png");
                this->addChild(lord,99);
                lord->setPosition(ccpAdd(spriteFont->getPosition(), ccp(0, -lord->getContentSize().height*1.2)));
                CCSprite *font = CCSprite::createWithSpriteFrameName("font_zj.png");
                this->addChild(font,100);
                font->setPosition(lord->getPosition());
                CCBlink *blink = CCBlink::create(10, 1);
                lord->runAction(CCRepeatForever::create(blink));
                CCBlink *blink1 = CCBlink::create(10, 1);
                font->runAction(CCRepeatForever::create(blink1));               
            }
			SGButton *spriteButton = SGButton::create(headString->getCString(), countryStr->getCString(), this,
                                                      menu_selector(SGFirstSubLayer::selectEmbattle),CCPointZero,false,true);
			spriteButton->addChild(countryName,30,30);
			CCMenu *menu1 = CCMenu::create();
            //头像的值
            int modelTag = SGStaticDataManager::shareStatic()->getGuideTagById(guide_tag_12);
            menu1->addChild(spriteButton);
            //对应的tag
            spriteButton->setTag(modelTag);
			this->addChild(menu1, 0, 124);
			menu1->setPosition(ccp(_viewSize.width/2, _viewSize.height/2));
            
            SGCCLabelTTF *advancenumber = NULL;
            if (temp->getAdvNum()>0)
            {
                advancenumber = SGCCLabelTTF::create(CCString::createWithFormat("+%d" , temp->getAdvNum())->getCString(),
                                                     FONT_PANGWA, 24,ccGREEN);
                advancenumber->setAnchorPoint(ccp(1,1));
                
                advancenumber->setPosition(spriteButton->getContentSize());
                spriteButton->addChild(advancenumber,50,550);
            }

            
            //如果可以转生  则显示红色叹号
            SGPlayerInfo * playerInfo = SGPlayerInfo::sharePlayerInfo();
            if(_officerCard->canShowNotice()  && playerInfo->getPlayerLevel() >= playerInfo->getShowPlayerNoticeLimitLev())
            {
                CCSprite * _spriteNotice = CCSprite::createWithSpriteFrameName("publc_notice.png");
                _spriteNotice->setPosition( ccpAdd(spriteButton->getPosition() , ccp(spriteButton->getContentSize().width  , spriteButton->getContentSize().height -3 ) ));
                this->addChild(_spriteNotice,1000);
            }
        }

    }
    else if(enterType == 2)
    {
        CCSprite *spriteHead = CCSprite::createWithSpriteFrameName("jinkuang.png");
        spriteHead->setPosition(ccp(_viewSize.width/2, _viewSize.height/2));
        addChild(spriteHead);
        
        CCSprite *suo = CCSprite::createWithSpriteFrameName("firstkuangSou.png");
        addChild(suo);
        suo->setPosition(spriteHead->getPosition());
        
        SGPlayerDataModel *player = SGStaticDataManager::shareStatic()->getPlayerByLevel(SGPlayerInfo::sharePlayerInfo()->getPlayerLevel());
        
		std::string str(player->getPlayerUnlockLevel()->getCString());
		str[0] = 'L';
		CCString *lvlLabelTmp = CCString::create(str);
		SGCCLabelTTF *lvLabel=SGCCLabelTTF::create(CCString::createWithFormat("%s",lvlLabelTmp->getCString())->getCString(),
                                                   FONT_BOXINFO, 34 , ccYELLOW);
        addChild(lvLabel);
        lvLabel->setPosition(ccpAdd(spriteHead->getPosition(), ccp(0, -suo->getContentSize().height/2+20)));
        
    }
    else if(enterType == 3)
    {
        SGButton *btn = SGButton::create("mainBtn_bg.png", "embattlekuang.png", this,
                                         menu_selector(SGFirstSubLayer::buttonClickOK),CCPointZero,false,true);
        bg->removeFromParent();
        CCMenu *menu = CCMenu::create(btn,NULL);
        this->addChild(menu,0,123);
        menu->setPosition(ccp(_viewSize.width/2, _viewSize.height/2));
    }

}
Ejemplo n.º 23
0
// initialize your instance here
Store::Store()
{
	
    //SaveLoad::m_SaveData.currency = 300000;
    //SaveLoad::SaveGame();
    // enable touches
    setTouchEnabled( true );
    
    float scale = ScreenHelper::getTextureScale();
    float scaleX = ScreenHelper::getTextureScaleX();
    float scaleY = ScreenHelper::getTextureScaleY();
    
    CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist");
    
    CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist");
    
    CCSprite *sprite = CCSprite::create("MainBackFiller.png");
    sprite->setScaleX(scaleX*1.2f);
    sprite->setScaleY(scaleY*1.2f);
    sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f));
    addChild(sprite);
    
    sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png");
    sprite->setScaleX(scaleX);
    sprite->setScaleY(scaleY);
    sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER));
    addChild(sprite,2);
    
    CCLabelTTF *label = CCLabelTTF::create("STORE", "impact.ttf", 42*scale);
    addChild(label, 2);
    label->setColor(ccc3(0,0,0));
    label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f));
    
    label = CCLabelTTF::create("STORE", "impact.ttf", 42*scale);
    addChild(label, 2);
    label->setColor(ccc3(237,188,0));
    label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f));
    
    CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(Store::backButtonTapped));
    BackButton->setScale(scale);
    BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f));
    ReturnButton = BackButton;
    
   
    CCSprite *spritePeanut = CCSprite::createWithSpriteFrameName("ctm_UI_Peanuts_Btn_ver1.png");
    CCSprite *spritePeanutDown = CCSprite::createWithSpriteFrameName("ctm_UI_Peanuts_Btn_Down.png");
    sprite = CCSprite::createWithSpriteFrameName("ctm_UI_PeanutsGlow_Btn_ver1.png");
    sprite->setPosition(ccp(136/2, 104/2));
    spritePeanut->addChild(sprite);
        
    CCMenuItem *PeanutsButton = CCMenuItemSprite::create(spritePeanut,spritePeanutDown,this,menu_selector(Store::peanutButtonTapped));
    
    PeanutsButton->setScale(scale);
    PeanutsButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,90.0f,130.0f));
    
    CCMenu* backmenu = CCMenu::create(BackButton, NULL);
    backmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT));
    addChild(backmenu,4);
    
    m_slideControl = CCNode::create();
    addChild(m_slideControl);
    
    CCMenu* peanutmenu = CCMenu::create(PeanutsButton, NULL);
    peanutmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT));
    m_slideControl->addChild(peanutmenu,4);
    
    
    CCScrollingMenu *screenMenu = CCScrollingMenu::create();
    screenMenu->setPosition(0,0);
    
    BuildUpgrades(screenMenu);
    BuildPowerUps(screenMenu);
    BuildCharacters(screenMenu);
    BuildBikes(screenMenu);
  
    screenMenu->alignItemsVerticallyWithPadding(-10*scaleY);
    CCSize viewSize;
    viewSize.width = 320.0f*scaleX;
    viewSize.height = 1450.0f*scaleY/(scaleY/scale);
    CCScrollView *scrollView = CCScrollView::create(viewSize,screenMenu);
    //scrollView->setBounceable(false);
    //temp = ComingSoonButton->getPositionX()/scaleX-480.0f;
    //temp += (ComingSoonButton->getContentSize().width)/scale;
    scrollView->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,160,275.0f*(scaleY/scale)-(viewSize.height/((scaleY+scale)/2.0f))/2.0f));
    scrollView->setContentSize(screenMenu->getContentSize());
    
    scrollView->setContentOffset(ccp(312.0f/2.0f*scaleX,0.0f));
    scrollView->setDirection(kCCScrollViewDirectionVertical);
    
    m_slideControl->addChild(scrollView);

    
    char currencyStr[32];
    sprintf(currencyStr,"$%d",SaveLoad::m_SaveData.currency);
    
    CCSize dim;
    dim.width = 100.0f;
    dim.height = 25.0f;
    
    m_currency = CCLabelBMFont::create(currencyStr,"JacobyICGBlack22pnt.fnt");
    m_currency->setScale(scale);
    m_currency->setAnchorPoint(ccp(1.0f,0.5f));
    m_currency->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,456, 238));
    addChild(m_currency,10);
    
    
    if(SaveLoad::m_SaveData.beenToStore==0)
    {
        SaveLoad::m_SaveData.beenToStore=1;
        SaveLoad::Save();
    //    [TestFlight passCheckpoint:@"STORE_VISIT"];
    }
    
    scheduleUpdate();
}
Ejemplo n.º 24
0
// 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));

    // 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);
    
    this->setKeypadEnabled(true);
    
    
    CCMenuItemImage *pItemPlay = CCMenuItemImage::create(
                                                         "playgameNormal.png", "playgameClose.png",this,menu_selector(HelloWorld::menuPlayGameCallback));
    pItemPlay->setPosition(ccp(visibleSize.width / 2, visibleSize.height*1.0f / 4.0f));
    pItemPlay->setScaleX(visibleSize.width / 600);
    pItemPlay->setScaleY(visibleSize.height / 400);
    
    CCMenu *pMenuPlay = CCMenu::create(pItemPlay, NULL);
    pMenuPlay->setPosition(CCPointZero);
    this->addChild(pMenuPlay, 1);
    
    CCSprite *pcSprite  = CCSprite::create("ScenceStart.png");
    pcSprite->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2));
    CCSize sz = pSprite->getContentSize();
    pcSprite->setScaleX(visibleSize.width / sz.width);
    pcSprite->setScaleY(visibleSize.height / sz.height);
    this->addChild(pcSprite, 0);
    
    return true;
}
Ejemplo n.º 25
0
bool MPMapLayer::init()
{
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
	// Exit button
    
    CCMenuItemImage *backItem = CCMenuItemImage::create(
                                                        "CloseNormal.png",
                                                        "CloseSelected.png",
                                                        this,
                                                        menu_selector(MPMapLayer::titleCallback));
    
	backItem->setPosition(ccp(origin.x + visibleSize.width - backItem->getContentSize().width/2 ,
                              origin.y + backItem->getContentSize().height/2));
    
    CCMenu* menu = CCMenu::create(backItem, NULL);
    menu->setPosition(CCPointZero);
    this->addChild(menu, 1);
    
	// Screen Title
    
    CCLabelTTF* label = CCLabelTTF::create("A Map Scene", "Arial", TITLE_FONT_SIZE);
    label->setPosition(ccp(origin.x + visibleSize.width/2,
                           origin.y + visibleSize.height - label->getContentSize().height));
    this->addChild(label, 1);
    
	// Tile Map
    
    //	CCTMXTiledMap *map = CCTMXTiledMap::create("MP_map/desert.tmx");
	CCTMXTiledMap *map = CCTMXTiledMap::create("andrew_map/andrew_tilemap.tmx");
    this->addChild(map, 0);

    MPMapLayer::antiAliasMap(map);
        
    map->setAnchorPoint(ccp(.5, .5));
    map->setPosition(ccp(visibleSize.width * .5, visibleSize.height * .5));
    map->setScale(.5);


    CCTMXLayer* layer = map->layerNamed("Background");
    assert(layer != NULL);
	
	CCTMXObjectGroup *objectGroup = map->objectGroupNamed("SpawnPointLayer");
	assert(objectGroup != NULL);
	CCSize mapSize = map->getContentSize();
	float mapHeight = mapSize.height;
	float mapWidth = mapSize.width;
	
	player = CCSprite::create("andrew_map/Player.png");
	CCDictionary *spawnPoint = objectGroup->objectNamed("SpawnPoint");
	
	map->addChild(player,1);
	
	const CCString *positionX = spawnPoint->valueForKey("x");
	const CCString *positionY = spawnPoint->valueForKey("y");
	const CCString *objectName = spawnPoint->valueForKey("name");
	
	std::cout << positionX->getCString() << std::endl;
	std::cout << mapHeight - positionY->intValue() % 32 << std::endl;
	std::cout << objectName->getCString() << std::endl;

//	player->setPosition(ccp(positionX,positionY));
	
/*
    CCSprite *tile = layer->tileAt(ccp(5,6));
    assert(tile != NULL);
    
    layer->removeTileAt(ccp(5, 6));
    
    CCActionInterval*  actionBy = CCMoveBy::create(2, ccp(visibleSize.width * .5, visibleSize.height * .5));
    map->runAction(actionBy);
    
    CCActionInterval* action = CCScaleBy::create(2, 2);
    map->runAction(action);
*/
    
    
/*
    CCSize s = layer->getLayerSize();
    for (int x = 2; x < s.width; x++) {
        for (int y = 0; y < s.height; y++) {
            layer->removeTileAt(ccp(x, y));
        }
    }
*/
    return true;
}
Ejemplo n.º 26
0
// on "init" you need to initialize your instance
bool SpriteDragger::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    this->setTouchEnabled(true);
    
    /////////////////////////////
    // 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(SpriteDragger::menuCloseCallback) );
    pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
    
    // create menu, it's an autorelease object
    CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu, 2);
    
    //color layer
    CCLayerColor* colorLayer = new CCLayerColor;
    colorLayer->initWithColor( ccc4(255, 255, 255, 255) );
    this->addChild(colorLayer, 1);
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    this->sprite = new CCSprite;
    this->sprite->initWithFile("Sprite.png");
    this->sprite->setPosition(ccp(winSize.width / 2.0f, winSize.height / 2.0f ));
    this->sprite->setAnchorPoint(ccp(0.5f, 0.55f));
    this->addChild(this->sprite);
    
    /*
    /////////////////////////////
    // 3. add your codes below...
    
    // add a label shows "Hello World"
    // create and initialize a label
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World SpriteDragger", "Thonburi", 34);
    
    // ask director the window size
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    
    // position the label on the center of the screen
    pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
    
    // 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(size.width/2, size.height/2) );
    
    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    */
    
    return true;
}
Ejemplo n.º 27
0
bool SettingScene::init()
{
	bool bRet = false;
	do 
	{
		this->setTouchEnabled(true);
		isMusicSwitchOn=sGlobal->isMusicOn;
		isEffectSwitchOn=sGlobal->isEffectOn;
		
		CCSprite* bgSprite=CCSprite::create("Startup_bkg_gray.jpg");
		bgSprite->setAnchorPoint(ccp(0,0));
		bgSprite->setPosition(ccp(0,0));

		addChild(bgSprite);

		CCSprite* bgSprite2=CCSprite::create("Startup_frame.png");
		//bgSprite->setAnchorPoint(ccp(0,0));
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		bgSprite2->setPosition(ccp(size.width / 2, size.height/2));
		//  float a=(float)480/800;
		// float b=(float)320/480;
		//  bgSprite2->setScaleX((float)480/800);
		//  bgSprite2->setScaleY((float)320/480);
		//bgSprite2->setScaleX(0.9f);
		//  bgSprite2->setScaleY(0.9f);
		addChild(bgSprite2);
		CCSprite* photo_border=CCSprite::create("Startup_photo_border.png");
		photo_border->setPosition(ccp(190,190));

		addChild(photo_border);
		CCSprite* herface=CCSprite::create("Option_gear.png");
		herface->setPosition(ccp(190,190));

		addChild(herface,2);
		CCSprite* option=CCSprite::create("Startup_lbl_option_zh.png");
		option->setPosition(ccp(size.width/2,240+120));

		addChild(option,2);

		CCSprite*  music=CCSprite::create("Option_lbl_music_zh.png");
		music->setPosition(ccp(size.width/2-30,240));

		addChild(music,2);

		CCSprite*  effect=CCSprite::create("Option_lbl_sound_zh.png");
		effect->setPosition(ccp(size.width/2-30,180));

		addChild(effect,2);
		musicSwitch=CCSprite::createWithSpriteFrame(sAnimationMgr->getSpritFrame(onkey));
		 effectSwitch=CCSprite::createWithSpriteFrame(sAnimationMgr->getSpritFrame(onkey));
		musicSwitch->setPosition(ccp(size.width/2+100,240));
		effectSwitch->setPosition(ccp(size.width/2+100,180));
		addChild(musicSwitch);
		addChild(effectSwitch);
		//......
		CCMenuItemImage *musicItem = CCMenuItemImage::create(
			"Option_btn_back_zh.png",
			"Option_btn_back_pressed_zh.png",
			this,
			menu_selector(SettingScene::musicItemCallback));
		musicItem->setPosition(ccp(size.width/2,120));
		CCMenu* pMenu = CCMenu::create(musicItem, NULL);
		pMenu->setPosition(CCPointZero);
		addChild(pMenu);
		//..............
		if (isMusicSwitchOn)
		{
			musicSwitch->setDisplayFrame(sAnimationMgr->getSpritFrame(onkey));

		}else
		{
			musicSwitch->setDisplayFrame(sAnimationMgr->getSpritFrame(offkey));

		}
		if (isEffectSwitchOn)
		{
			effectSwitch->setDisplayFrame(sAnimationMgr->getSpritFrame(onkey));

		}else
		{
			effectSwitch->setDisplayFrame(sAnimationMgr->getSpritFrame(offkey));

		}

		bRet=true;
	}while(0);
	return bRet;

}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());

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

        // 1. Add a menu item with "X" image, which is clicked to quit the program.
		CCMenuItemFont::setFontName("Arial");
//		CCMenuItem *item1 = CCMenuItemFont::itemWithString("Start",this,);
        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
            "CloseNormal.png",
            "CloseSelected.png",
            this,
            menu_selector(HelloWorld::menuCloseCallback));
        CC_BREAK_IF(! pCloseItem);

        // Place the menu item bottom-right conner.
        pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);

        // 2. Add a label shows "Hello World".

        // Create a label and initialize with string "Hello World".
        CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
        CC_BREAK_IF(! pLabel);

        // Get window size and place the label upper. 
        CCSize size = CCDirector::sharedDirector()->getWinSize();
        pLabel->setPosition(ccp(size.width / 2, size.height - 50));

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

        // 3. Add add a splash screen, show the cocos2d splash image.
        CCSprite* pSprite = CCSprite::create("HelloWorld.png");
        CC_BREAK_IF(! pSprite);

        // Place the sprite on the center of the screen
        pSprite->setPosition(ccp(size.width/2, size.height/2));

        // Add the sprite to HelloWorld layer as a child layer.
        this->addChild(pSprite, 0);

        bRet = true;
    } while (0);

    return bRet;
}
Ejemplo n.º 29
0
bool LoginScene::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    
    //buttons 
    CCMenuItemImage *pRegister = CCMenuItemImage::create(
                                                    "wkszLogin/register.png",
                                                    "wkszLogin/register_p.png",
                                                    this,
                                                    menu_selector(LoginScene::registerCB) );
    CCMenuItemImage *pLogin = CCMenuItemImage::create(
                                                     "wkszLogin/login.png",
                                                     "wkszLogin/login_p.png",
                                                     this,
                                                     menu_selector(LoginScene::loginCB) );
    CCMenuItemImage *pSurfer = CCMenuItemImage::create(
                                                    "wkszLogin/surfer.png",
                                                    "wkszLogin/surfer_p.png",
                                                    this,
                                                    menu_selector(LoginScene::surferCB) );
    
    pRegister->setPosition( ccp(500, 100) );
    pLogin->setPosition( ccp(650, 450) );
    pSurfer->setPosition( ccp(650, 380) );
    
    CCMenu* pMenu = CCMenu::create(pRegister,pLogin,pSurfer,NULL);
    pMenu->setPosition( CCPointZero );
    this->addChild(pMenu);
    
    
    //editbox
    CCScale9Sprite * ssp1 = CCScale9Sprite::create("wkszLogin/editboxBG.png");
    ssp1->setPreferredSize(CCSizeMake(500, 20));
    ssp1->setAnchorPoint(ccp(0.5, 0.5));
    pEditBox = CCEditBox::create(CCSizeMake(200,40),ssp1);
    pEditBox->setPlaceHolder("输入用户名");
    pEditBox->setFontColor(ccc3(255, 0, 255));
    pEditBox->setPosition(ccp(450, 450));
    this->addChild(pEditBox);
    
    CCScale9Sprite * ssp2 = CCScale9Sprite::create("wkszLogin/editboxBG.png");
    ssp2->setPreferredSize(CCSizeMake(500, 20));
    ssp2->setAnchorPoint(ccp(0.5, 0.5));
    pEditBoxPWD = CCEditBox::create(CCSizeMake(200,40),ssp2);
    pEditBoxPWD->setPlaceHolder("输入密码");
    pEditBoxPWD->setFontColor(ccc3(255, 0, 255));
    pEditBoxPWD->setPosition(ccp(450, 380));
    pEditBoxPWD->setInputFlag(kEditBoxInputFlagPassword);
    this->addChild(pEditBoxPWD);

    
    //mssages
    CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
    this->addChild(pLabel, 1);
    
    swfBg = CCSWFNode::create("wkszLogin/swfBg.swf");
    swfBg->setPosition(ccp(size.width/2+30, size.height/2-100));
    swfBg->setScale(0.8f);
    swfBg->runAction();
    swfBg->setRepeat(true);
    this->addChild(swfBg,-9);
    
    swfWK = CCSWFNode::create("wkszLogin/swfWK.swf");
    swfWK->setPosition(ccp(800, 280));
    swfWK->runAction();
    swfWK->setRepeat(true);
    this->addChild(swfWK,-8);

    
    CCSprite *sptmp = CCSprite::create("wkszLogin/tree.png");
    sptmp->setPosition(ccp(920,80));
    this->addChild(sptmp,-7);
    
    
    swfMovie = NULL;
    flag = 0;
    return true;
}
Ejemplo n.º 30
0
// on "init" you need to initialize your instance
bool CGameMenu::init()
{
    bool bRet = false;
    do
	{
		CC_BREAK_IF(! CCLayer::init());
		CCSize size = CCDirector::sharedDirector()->getWinSize();
		
		// 菜单列表
		CCSpriteFrameCache *pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
		pCache->addSpriteFramesWithFile("Image/GameMenu.plist");

		// 菜单背景
		CCSprite* m_pBackground = CCSprite::createWithSpriteFrame(pCache->spriteFrameByName("Background.png"));
		m_pBackground->setPosition(ccp(size.width/2, size.height/2));
		this->addChild(m_pBackground, 0);
		
		//	星星	
		CCSprite* pStar = CCSprite::create("Image/Star.png");
		CC_BREAK_IF(! pStar);
		pStar->setPosition(ccp(size.width/2, size.height/2));
        this->addChild(pStar, 1);
		
		CCActionInterval* actionFade = CCFadeOut::create(2.0f);
		CCActionInterval* actionFadeBack = actionFade->reverse();
		CCActionInterval* seq2 = (CCActionInterval*)CCSequence::create(actionFade, actionFadeBack, NULL);
		CCRepeatForever* pRepeatForever = CCRepeatForever::create(seq2);
		pStar->runAction(pRepeatForever);

		// 标题
		CCSprite* pTitle = CCSprite::create("Image/Title.png");
		CC_BREAK_IF(! pTitle);
		pTitle->setPosition(ccp(size.width/2, size.height - 70));
        this->addChild(pTitle, 2);

		// 开始游戏
		CCMenuItemImage *pMenuStart = CCMenuItemImage::create();
		//pMenuStart->initWithTarget(this, menu_selector(CGameMenu::menuStartCallback));
		pMenuStart->setCallback( CC_CALLBACK_1(CGameMenu::menuStartCallback,this) );
		pMenuStart->setNormalSpriteFrame(pCache->spriteFrameByName("StartNormal.png"));  
		pMenuStart->setSelectedSpriteFrame(pCache->spriteFrameByName("StartSelected.png"));
		pMenuStart->setPosition(ccp(size.width/2, 110));
		
		//	游戏配置
		CCMenuItemImage *pMenuOption = CCMenuItemImage::create();       
		//pMenuOption->initWithTarget(this, menu_selector(CGameMenu::menuOptionCallback));
		pMenuOption->setCallback( CC_CALLBACK_1(CGameMenu::menuOptionCallback,this) );
		pMenuOption->setNormalSpriteFrame(pCache->spriteFrameByName("OptionNormal.png"));  
		pMenuOption->setSelectedSpriteFrame(pCache->spriteFrameByName("OptionSelected.png"));
		pMenuOption->setPosition(ccp(size.width/2, 75));

		// 游戏结束
		CCMenuItemImage *pMenuExit = CCMenuItemImage::create();       
		//pMenuExit->initWithTarget(this, menu_selector(CGameMenu::menuExitCallback));
		pMenuExit->setCallback( CC_CALLBACK_1(CGameMenu::menuExitCallback,this) );
		pMenuExit->setNormalSpriteFrame(pCache->spriteFrameByName("ExitNormal.png"));  
		pMenuExit->setSelectedSpriteFrame(pCache->spriteFrameByName("ExitSelected.png"));
		pMenuExit->setPosition(ccp(size.width/2, 40));
		 
		// 游戏菜单
		CCMenu *pMenu = CCMenu::create(pMenuStart,pMenuOption, pMenuExit, NULL);
		pMenu->setPosition(ccp(0, 0));
		this->addChild(pMenu, 3);
		
		// 陨石掉落特效
		m_pMeteorolite = CCParticleSun::create();
		m_pMeteorolite->setTexture(CCTextureCache::sharedTextureCache()->addImage("Image/Fire.png"));
		this->addChild(m_pMeteorolite, 1);
		move(0);
		this->schedule(schedule_selector(CGameMenu::move), 5.0f);
		
		// 飞机
		CCSprite* pPlane = CCSprite::create("Image/PlaneIco.png");
		CC_BREAK_IF(! pPlane);
		pPlane->setPosition(ccp(size.width/2, size.height/2));
        this->addChild(pPlane, 2);
		
		bRet = true;
	}
	while(0);

    return bRet;
}