cocos2d-x编程之CCScale9Sprite典型用法
更新:HHH   时间:2023-1-7


cocos2d-x编程之CCScale9Sprite典型用法


STEP 1:使用PHOTOSHOP制作原始的小的图片(SIZE: 200 x100),如下图所示。


STEP 2: C++编码。

  CCSprite* tmp = CCSprite::create("scale.png");
    CCSize size = tmp->getContentSize();

//创建原始的图像对应大小矩形区域。
    CCRect fullRect = CCRectMake(0,0, size.width, size.height);

//创建内部区域对应的矩形大小
//注意:(11,11)这个点最关键,对应于上图中内部棕色矩形左上角的坐标
//于是insetRect 即对应于内部的棕色矩形区域
//实际应用中,我们要对这个内部区域进行放大或者缩小使用
    CCRect insetRect = CCRectMake(11, 11,size.width-11*2, size.height-11*2);

    CCScale9Sprite* pSprite = CCScale9Sprite::create("scale.png",fullRect,insetRect);

    pSprite->setContentSize(CCSizeMake(400,200));
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    this->addChild(pSprite, 0);

本例中,我们要创建大小为400X200大小的屏幕精灵。

STEP 3:上述代码运行结果如下。






无标题.jpg

无标题.jpg


返回游戏开发教程...