void touchEvent(Ref *pSender, cocos2d::ui::Widget::TouchEventType type);
cocos2d::LayerColor* _baseLayer;
void HelloWorld::init2();
------------------------------------------------------------------------------------------------------------
Size widgetSize = Director::getInstance()->getVisibleSize();
_baseLayer = LayerColor::create();
_baseLayer->setColor(Color3B(50, 100, 0));
_baseLayer->setOpacity(100);
_baseLayer->setContentSize(Size(200, 200));
this->addChild(_baseLayer);
Button* button = Button::create("animationbuttonnormal.png");
CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
button->getContentSize().height);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->addTouchEventListener(CC_CALLBACK_2(HelloWorld::touchEvent, this));
button->setZoomScale(0.4f);
button->setPressedActionEnabled(true);
this->addChild(button);
void HelloWorld::touchEvent(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::BEGAN:
break;
case Widget::TouchEventType::MOVED:
break;
case Widget::TouchEventType::ENDED:
{
Size widgetSize = Director::getInstance()->getVisibleSize();
Size layerSize = Size(300,200);
if (layerSize.width == widgetSize.width && layerSize.height == widgetSize.height)
_baseLayer->setContentSize(Size(200, 200));
else
_baseLayer->setContentSize(widgetSize);
//ui:Helper::doLayout(_baseLayer);
init2();
}
break;
case Widget::TouchEventType::CANCELED:
break;
default:
break;
}
}
void HelloWorld::init2()
{
Sprite* leftTopSprite = Sprite::create("CloseSelected.png");
LayoutComponent* leftTop = LayoutComponent::bindLayoutComponent(leftTopSprite);
leftTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
leftTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
_baseLayer->addChild(leftTopSprite);
Sprite* leftBottomSprite = Sprite::create("CloseSelected.png");
LayoutComponent* leftBottom = LayoutComponent::bindLayoutComponent(leftBottomSprite);
leftBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Left);
leftBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
_baseLayer->addChild(leftBottomSprite);
Sprite* rightTopSprite = Sprite::create("CloseSelected.png");
LayoutComponent* rightTop = LayoutComponent::bindLayoutComponent(rightTopSprite);
rightTop->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
rightTop->setVerticalEdge(LayoutComponent::VerticalEdge::Top);
_baseLayer->addChild(rightTopSprite);
Sprite* rightBottomSprite = Sprite::create("CloseSelected.png");
LayoutComponent* rightBottom = LayoutComponent::bindLayoutComponent(rightBottomSprite);
rightBottom->setHorizontalEdge(LayoutComponent::HorizontalEdge::Right);
rightBottom->setVerticalEdge(LayoutComponent::VerticalEdge::Bottom);
_baseLayer->addChild(rightBottomSprite);
ui::Helper::doLayout(_baseLayer);
}