1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //这是用于显示3D鱼模型的层 class FishLayer : public cocos2d:ayer { public: //初始化当前层 virtual bool init(); CREATE_FUNC(FishLayer); protected: //鱼精灵 cocos2d::Sprite3D*_sprite; //向前游的动作 cocos2d::Animate3D*_swim; //受伤的动作 cocos2d::Animate3D*_hurt; }; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | bool FishLayer::init() { //加载模型文件 std::string fileName = "tortoise.c3b"; _sprite = Sprite3D::create(fileName); _sprite->setScale(0.1f); auto s = Director::getInstance()->getWinSize(); _sprite->setPosition(Vec2(s.width * 4.f / 5.f, s.height / 2.f)); addChild(_sprite); //获取骨骼动画信息 auto animation = Animation3D::create(fileName); if (animation) { //从起始到1.933秒截取为游泳动作 _swim = Animate3D::create(animation, 0.f, 1.933f); _swim->retain(); //从1.933秒到2.8秒截取为受伤的动作 _hurt = Animate3D::create(animation, 1.933f, 2.8f); _hurt->retain(); //让精灵循环播放游泳和的受伤动作 Sequence*pSequence = Sequence::create(_swim,_hurt,NULL); _sprite->runAction(RepeatForever::create(pSequence)); } return true; } |
欢迎光临 让生活充满乐趣 (http://www.ofunny.com/) | Powered by Discuz! 7.0.0 |