bool UndercoverGameScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    ControlButton* back = ControlButton::create("Back", "Arial", 40);
    back->addTargetWithActionForControlEvents(this, cccontrol_selector(UndercoverGameScene::buttonBack), Control::EventType::TOUCH_UP_INSIDE);
    back->setAnchorPoint(Point(0.5,0.5));
    back->setZoomOnTouchDown(true);
    back->setPosition(Vec2(visibleSize.width - 100,
                           visibleSize.height - 100));
    this->addChild(back, 1);
    return true;
}
Exemplo n.º 2
0
ControlButton * createBtn(float x, float y, 
						  const char * normalBg, const char * pressBg, 
						  Ref* target, Control::Handler action)
{
	Scale9Sprite * spNormalBg = createDotaScale9Sprite(normalBg);
	Scale9Sprite * spPressBg = createDotaScale9Sprite(pressBg);

	ControlButton *btn = ControlButton::create(spNormalBg);
	if (spPressBg)
		btn->setBackgroundSpriteForState(spPressBg, Control::State::HIGH_LIGHTED);
	btn->setAnchorPoint(Vec2(0, 0));
	btn->setPosition(x, y);
	btn->setZoomOnTouchDown(false);
	btn->setPreferredSize(spNormalBg->getOriginalSize());
	if (target && action)
		btn->addTargetWithActionForControlEvents(target, action, 
			Control::EventType::TOUCH_UP_INSIDE);

	return btn;
}