refactor: 将数学工具函数移至GameMath类 feat(音频): 实现地图音频控制器 feat(调试): 添加游戏调试UI组件 feat(地图): 增加移动区域边界获取方法 fix(角色): 修复角色移动区域抑制逻辑 refactor(世界): 重构游戏世界场景初始化 docs(音频): 完善音频数据库注释
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <frostbite2D/base/RefObject.h>
|
|
#include <frostbite2D/types/type_alias.h>
|
|
#include <string>
|
|
#include <SDL2/SDL_mixer.h>
|
|
|
|
namespace frostbite2D {
|
|
|
|
/**
|
|
* @brief 音乐类
|
|
*
|
|
* 用于加载和播放长音频文件(背景音乐),支持从文件或内存加载。
|
|
* 支持 WAV、OGG、MP3 等格式。
|
|
*/
|
|
class Music : public RefObject {
|
|
public:
|
|
static Ptr<Music> loadFromPath(const std::string& path);
|
|
static Ptr<Music> loadFromFile(const std::string& path);
|
|
static Ptr<Music> loadFromMemory(const uint8* data, size_t size);
|
|
static Ptr<Music> loadFromNpk(const std::string& audioPath);
|
|
static bool isPathPlaying(const std::string& path);
|
|
static std::string getCurrentPlayingPath();
|
|
|
|
~Music();
|
|
|
|
bool play(int loops = -1);
|
|
bool fadeIn(int ms, int loops = -1);
|
|
void pause();
|
|
void resume();
|
|
void stop();
|
|
bool fadeOut(int ms);
|
|
|
|
void setVolume(float volume);
|
|
float getVolume() const;
|
|
|
|
bool isPlaying() const;
|
|
bool isPaused() const;
|
|
|
|
const std::string& getPath() const { return path_; }
|
|
|
|
private:
|
|
Music(Mix_Music* music, const std::string& path = "");
|
|
Music(Mix_Music* music, std::vector<uint8> data, const std::string& path = "");
|
|
|
|
Mix_Music* music_ = nullptr;
|
|
std::string path_;
|
|
std::vector<uint8> data_;
|
|
float volume_ = 1.0f;
|
|
};
|
|
|
|
}
|