首页 > 代码库 > Cocos2d-x3.2 Speed、Follow的使用
Cocos2d-x3.2 Speed、Follow的使用
//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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。