您的位置:首页 > 移动开发 > Cocos引擎

【独立开发者er Cocos2d-x实战 005】使用Cocos2dx Scale9Sprite使用

2015-07-10 16:50 471 查看
CCScale9Sprite类,有人叫它点九图,有人叫它九宫图,有人叫它九妹图。现在我们就来对他进行简单的使用。

CCSpriteFrameCache * cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("Plist.plist");

CCSprite *room = CCSprite::createWithSpriteFrameName("6.png");
CCPoint oPoint = room->getContentSize();/* 66,27 */
room->setPosition(ccp(100, 100));
room->setScale(4.0f);
addChild(room);

Scale9Sprite *poScale9Sprite1 = Scale9Sprite::createWithSpriteFrameName("6.png");
poScale9Sprite1->setPosition(ccp(100, 300));
poScale9Sprite1->setContentSize(CCSizeMake(oPoint.x * 4, oPoint.y * 4));
addChild(poScale9Sprite1);

Scale9Sprite *poScale9Sprite2 = Scale9Sprite::createWithSpriteFrameName("6.png");
poScale9Sprite2->setPosition(ccp(100, 500));
poScale9Sprite2->setCapInsets(CCRect(3,3,oPoint.x - 3, oPoint.y - 3));
poScale9Sprite2->setContentSize(CCSizeMake(oPoint.x * 4, oPoint.y * 4));
addChild(poScale9Sprite2);


运行结果如下(这里放大倍数不够大,如果更加大的话效果很明显):



在使用CCScale9Sprite时我们需要特别注意设置capInsets:



由于CCScale9Sprite属于扩展,在extensions文件夹下,所以我们使用中,需要加上相应的头文件和名空间:

#include "../extensions/cocos-ext.h"
USING_NS_CC_EXT;


同时也要添加相关路径:



否则出现下述错误:



#

参考文章:

cocos2dx 3.x Scale9Sprite的认识

cocos2dx基础篇(12)——点九图CCScale9Sprite

#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: