查了好久,今天才在官网论坛找到了方法,因为好像3.3之后就不是导一个现有项的那种方法了。闲话不多说,创建方法只需要两步
- #include “ui\UIScale9Sprite.h”
- 使用的时候这样写才能不出错
auto nineGirl = ui::Scale9Sprite::create(“button.png”);
贴一个自己的非常简单的代码
#include "HelloWorldScene.h"
#include "ui\UIScale9Sprite.h"
using namespace cocos2d;
Scene* HelloWorld::createScene()
{
// 'scene' is an autorelease object
auto scene = Scene::create();
// 'layer' is an autorelease object
auto layer = HelloWorld::create();
// add layer as a child to scene
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto nineGirl = ui::Scale9Sprite::create("button.png");
nineGirl->setContentSize(Size(200,200));
nineGirl->setPosition(Vec2(200,200));
this->addChild(nineGirl);
return true;
}
void HelloWorld::menuCloseCallback(Ref* pSender)
{
Director::getInstance()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
exit(0);
#endif
}
再次感谢这两位仁兄,出处:官方论坛-3.4 中如何使用Scale9Sprite