Extra2D/examples/flappy_bird/ResLoader.h

64 lines
1.5 KiB
C
Raw Normal View History

// ============================================================================
// ResLoader.h - 资源加载器
// 描述: 管理游戏资源的加载和访问
// ============================================================================
#pragma once
#include <extra2d/extra2d.h>
#include <map>
#include <string>
namespace flappybird {
/**
* @brief
*/
enum class MusicType {
Click, // 按键声音
Hit, // 小鸟死亡声音
Fly, // 小鸟飞翔声音
Point, // 得分声音
Swoosh // 转场声音
};
/**
* @brief
*
*/
class ResLoader {
public:
/**
* @brief
*/
static void init();
/**
* @brief
* @param name
* @return
*/
static extra2d::Ptr<extra2d::SpriteFrame> getKeyFrame(const std::string& name);
/**
* @brief
* @param type
*/
static void playMusic(MusicType type);
private:
/**
* @brief
* atlas.txt : width height x y
*/
struct ImageInfo {
float width, height, x, y;
};
static extra2d::Ptr<extra2d::Texture> atlasTexture_; // 图集纹理
static std::map<std::string, ImageInfo> imageMap_; // 图片信息映射
static std::map<MusicType, extra2d::Ptr<extra2d::Sound>> soundMap_; // 音效映射
};
} // namespace flappybird