cocos2dx3.3开发FlappyBird总结十:背景层设计
来源:互联网 发布:网络博客 国家 编辑:程序博客网 时间:2024/05/17 02:02
游戏背景层的任务是很简单的,只是根据当前时间来显示白天或者黑夜背景图,提供获取地面的高度方法。
#ifndef __EngryBird__BackgroundLayer__#define __EngryBird__BackgroundLayer__#include "cocos2d.h"/** * The game background,showing the background information * in the game. */class BackgroundLayer : public cocos2d::Layer {public: /** * The default constructor */ BackgroundLayer(); /** * The default destructor */ ~BackgroundLayer(); /** * The init method, will init the super init method first * * @return true if succeeded, otherwise false */ virtual bool init(); CREATE_FUNC(BackgroundLayer); /** * Get the land sprite height * * @return The height of land */ static float getLandHeight();};#endif /* defined(__EngryBird__BackgroundLayer__) */
背景层的实现中,看看怎么判断是不是白天或者黑夜。
bool BackgroundLayer::init() { if (!Layer::init()) { return false; } // Get the current time, judge whether now is day or night time_t t = time(NULL); tm *localTime = localtime(&t); int hour = localTime->tm_hour; std::string bgName; if (hour >= 6 && hour <= 17) { bgName = "bg_day"; } else { bgName = "bg_night"; } auto bgSprite = Sprite::createWithSpriteFrame(AtlasLoader::getInstance()->getSpriteFrame(bgName)); // 这里设置成(0,0),就可以从左下角开始显示至全屏 bgSprite->setAnchorPoint(Vec2::ZERO); bgSprite->setPosition(Vec2::ZERO); this->addChild(bgSprite); return true;}
获取地面的高度:
// 其实就是加载地面精灵,然后获取其内容大小的高度float BackgroundLayer::getLandHeight() { auto spriteFrame = AtlasLoader::getInstance()->getSpriteFrame("land"); auto land = Sprite::createWithSpriteFrame(spriteFrame); return land->getContentSize().height;}
下一步,说说控制层(选项层)
0 0
- cocos2dx3.3开发FlappyBird总结十:背景层设计
- cocos2dx3.3开发FlappyBird总结十二:状态层设计
- cocos2dx3.3开发FlappyBird总结一:背景介绍
- cocos2dx3.3开发FlappyBird总结十一:控制层功能设计
- cocos2dx3.3开发FlappyBird总结十六:游戏层实现
- cocos2dx3.3开发FlappyBird总结十七:结束语
- cocos2dx3.3开发FlappyBird总结六:设计共享小鸟类(主角)
- cocos2dx3.3开发FlappyBird总结三:项目剖析
- cocos2dx3.3开发FlappyBird总结四:资源管理类
- cocos2dx3.3开发FlappyBird总结五:说说屏幕适配
- cocos2dx3.3开发FlappyBird总结七:说说游戏流程
- cocos2dx3.3开发FlappyBird总结八:载入场景LoadingScene
- cocos2dx3.3开发FlappyBird总结九:欢迎场景(WelcomeScene)
- cocos2dx3.3开发FlappyBird总结十三:数字特效类
- cocos2dx3.3开发FlappyBird总结十四:常量定义
- cocos2dx3.3开发FlappyBird总结十五:记录玩家得分
- FlappyBird开发总结(五)——背景延伸
- 背景与小鸟--FlappyBird游戏开发教程之二
- 碰到个奇怪的memory leak.
- MySQL: ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
- 一次谷歌面试趣事
- bzoj1260: [CQOI2007]涂色paint dp
- flex可以通过中间件tomcat发布成web项目
- cocos2dx3.3开发FlappyBird总结十:背景层设计
- <s:iterator>如何实现一行显示指定个数的值
- div span的区别
- 0x4 python 转exe
- 99乘法表 c艹练习
- netty in action第一章netty介绍
- Android uses-permission 权限大全
- matlab导入数据文件
- fdsgsdg