Cocos2d-x:使用九宫格(九切片)自定义缩放资源

  从开发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));        

 

posted @ 2017-05-25 16:51  Kim_0908  阅读(2167)  评论(0)    收藏  举报