Cocos2d-x3.2 Scale 9 Sprite点9図形式で画像をスケール
1554 ワード
//GameScene.h
#include "cocos2d.h"
class GameScene : public cocos2d::Layer
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
void menuCallback(cocos2d::Ref* pSender);
CREATE_FUNC(GameScene);
};
//GameScene.cpp
// : , 。 !
#include "GameScene.h"
// Scale9Sprite
#include "extensions/cocos-ext.h"
USING_NS_CC_EXT;
USING_NS_CC;
cocos2d::Scene* GameScene::createScene()
{
auto scene = Scene::create(); //
auto layer = GameScene::create(); //
scene->addChild(layer);
return scene;
}
//
bool GameScene::init()
{
if(!Layer::init()) //
return false;
//
Size visibleSize = Director::getInstance()->getVisibleSize();
//auto size = Director::getInstance()->getWinSize();
auto sprite2 = Sprite::create("yellow_edit.png");
sprite2->setPosition(Vec2(visibleSize.width/2, visibleSize.height*0.7));
addChild(sprite2);
auto sprite3 = Sprite::create("yellow_edit.png");
sprite3->setPosition(Vec2(visibleSize.width/2, visibleSize.height*0.6));
sprite3->setScaleX(5);
addChild(sprite3);
auto sprite1 = Scale9Sprite::create("yellow_edit.png");
sprite1->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
addChild(sprite1);
//
sprite1->setPreferredSize(Size(Vec2(300, 50)));
//
sprite1->setCapInsets(Rect(10, 10, 8, 8));
return true;
}