コード例 #1
0
ファイル: StageLayer.cpp プロジェクト: windswhisper/cocos2d
void MyListView::add_option(const char* name)
{
	Sprite* option = Sprite::create("situ_item_background_normal.png");
	
	option->setPosition(0,-options_vec.size()*option_height-option_height);

	option->setCascadeOpacityEnabled(true);

	option->setOpacity(0);

	LabelTTF* label = LabelTTF::create(name,"Arial",50);

	label->setFontFillColor(Color3B(249,222,144));

	label->setPosition(option->getBoundingBox().size.width/2,option->getBoundingBox().size.height/2);

	option->addChild(label);

	this->addChild(option);

	this->options_vec.pushBack(option);

	if(options_vec.size()*option_height+option_height>height)
	{
		height = options_vec.size()*option_height+option_height;
	}
}
コード例 #2
0
ファイル: LevelStartView.cpp プロジェクト: tinyCome/Solitaire
void LevelStartView::initPropList(cocos2d::Layer * pStart)
{
	std::vector<std::string> propList;

	getPropListData(propList);
	
	size_t i = 0;
	for (std::map<std::string, std::string>::iterator it = m_propList.begin(); it != m_propList.end(); ++it)
	{
		Sprite* pPropList = static_cast<Sprite *>(pStart->getChildByName(propList.at(i++)));
		Size s = pPropList->getContentSize();

		Sprite* pProp = Sprite::create(it->first);
		pProp->setScale(1.2f);
		pProp->setPosition(s.width / 2, s.height / 2);
		pProp->setTag(i + 1);
		pPropList->addChild(pProp);

		LabelTTF* propFee = LabelTTF::create(it->second, "fonts/Marker Felt.ttf",36);
		propFee->setFontFillColor(ccc3(126, 126, 126));
		propFee->setPosition(s.width-20, -s.height/2+20);
		pPropList->addChild(propFee);

		auto listener = EventListenerTouchOneByOne::create();
		listener->setSwallowTouches(true);
		listener->onTouchBegan = CC_CALLBACK_2(LevelStartView::onTouchBegan, this);
		listener->onTouchMoved = CC_CALLBACK_2(LevelStartView::onTouchMoved, this);
		listener->onTouchEnded = CC_CALLBACK_2(LevelStartView::onTouchEnded, this);
		this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, pProp);
	}
}