从开发iOS起地九切片技术的使用就不熟练,最近遇到的需求是要根据麻将牌的数量来适应背景图片,下面就是有效的实现缩放的方法:
//9宫格图片 //确定大小 ImageView *imageBg = ImageView::create("smallBG.png"); Rect fullRect = Rect(0,0, imageBg->getContentSize().width, imageBg->getContentSize().height); Rect insetRect = Rect(10,10,imageBg->getContentSize().width-20, imageBg->getContentSize().height-20); //创建九宫格精灵 auto sSprite = cocos2d::ui::Scale9Sprite::create("smallBG.png",fullRect, insetRect); sSprite->setAnchorPoint(Vec2(0, 0)); sSprite->setContentSize(Size(Vec2(allCardWidth + (m_iMaimaCnt) * 5 + 25, imageBg->getContentSize().height))); sSprite->setPosition(Vec2(30, 2));