CCControlButton的使用

原文链接:http://blog.sina.com.cn/s/blog_7d1531ed010167pq.html


CCControlButton 是cocos2d-x新封装的UI 类似oc的UIButton 可以设置各个状态的png支CCScale9Sprite根据大小拉伸图片!

CCControlButton的使用CCControlButton的使用


CCSprite* tmp = CCSprite::create("CloseNormal.png");

    CCSize size =tmp->getContentSize();

    CCLog("wh:%f,%f", size.width, size.height);

   tmp->release();

   CCScale9Sprite* backGround = CCScale9Sprite::create("CloseNormal.png");

   CCControlButton*button=CCControlButton::create(backGround);

   button->setPosition(200, 200);

    

   button->setPreferredSize(CCSizeMake(size.width, size.height));

    this->addChild(button);

   button->addTargetWithActionForControlEvents(this,cccontrol_selector(HelloWorld::menu1Callback), CCControlEventTouchUpInside);

 

voidHelloWorld::menu1Callback(cocos2d::CCNode *pSender)

{

   CCControlButton*button=(CCControlButton*)pSender;

   CCLog("%d",button->getTag());//根据tag值判断按钮

   CCLOG("menu1Callback");

}

如果button->setPreferredSize(CCSizeMake(size.width*3,size.height*3));就会变成第二张图片走形了

疑惑的是 CCScale9Sprite有什么作用是为了适应button的拉扯 效果还是那么难看!

解决办法:对CCScale9Sprite进行缩放规划才可以

 

CCSprite* tmp= CCSprite::create("CloseNormal.png");

   CCSize size =tmp->getContentSize();

 

CCRectfullRect = CCRectMake(0,0,size.width, size.height);

   CCRect insetRect = CCRectMake(2,2,size.width-4, size.height-4);

CCScale9Sprite* backGround = CCScale9Sprite::create("CloseNormal.png", fullRect,insetRect);

CCControlButton的使用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值