Cocos2d-x学习一:Sprite

//Initialize background
		CCSprite *pSprite = CCSprite::create("ui_background_normalbg.png");
		CC_BREAK_IF(!pSprite);

		CCSize size = CCDirector::sharedDirector()->getWinSize();
		pSprite->setPosition(ccp(size.width/2, size.height/2));

		this->addChild(pSprite, 0);

		CCSprite *titleSprite = CCSprite::create("main_ui_title_cn_hv.png");
		CC_BREAK_IF(!titleSprite);
		CCSize titleSize = titleSprite->getContentSize();
		titleSprite->setPosition(ccp(size.width/2, size.height - titleSize.height/2));

		this->addChild(titleSprite, 1);

		//Initiliza Sprite Cache
		CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
		cache->addSpriteFramesWithFile("UI_GameMenuText_cn.plist");
		CCSprite *beginBtnSprite = CCSprite::createWithSpriteFrameName("ui_2p_010.png");
		CC_BREAK_IF(!beginBtnSprite);
		//
	    CCSpriteFrame *startFrame = new CCSpriteFrame();
		startFrame = cache->spriteFrameByName("ui_2p_010.png");

		CCSpriteFrame *startFrame2 = new CCSpriteFrame();
		startFrame2 = cache->spriteFrameByName("button_other_026_1.png");
		//this->addChild(beginBtnSprite, 1);
		beginBtnSprite->setPosition(ccp(size.width/2, size.height/2));

		CCMenuItemImage *start = CCMenuItemImage::create(NULL,  
            NULL,  
            this,  
            menu_selector(HelloWorld::selectGame));
		start->setNormalSpriteFrame(startFrame);
		start->setSelectedSpriteFrame(startFrame2);
		start->setPosition(ccp(size.width/2, size.height/2));

		CCMenu *menu = CCMenu::create(start, NULL);
		menu->setPosition(ccp(0,0));
		this->addChild(menu,1);

你可能感兴趣的:(cocos2d-x)