Cocos2d-x3.2 Speed、Followの使用
1449 ワード
//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"
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 sprite = Sprite::create("OnePiece_1.png");
sprite->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
this->addChild(sprite);
auto sprite1 = Sprite::create("Icon.png");
sprite1->setPosition(Vec2(visibleSize.width*0.2, visibleSize.height/2));
this->addChild(sprite1);
auto moveTo = MoveTo::create(2, Vec2(visibleSize.width*0.8, visibleSize.height/2));
//sprite1->runAction(moveTo);
//
auto speed = Speed::create(moveTo, 2);
sprite1->runAction(speed);
//
auto follow = Follow::create(sprite1);
this->runAction(follow);
return true;
}