#pragma once #include #include #include #include namespace frostbite2D { /** * @brief 音效类 * * 用于加载和播放短音频文件,支持从文件或内存加载。 * 支持 WAV、OGG 等格式。 */ class Sound : public RefObject { public: static Ptr loadFromPath(const std::string& path); static Ptr loadFromFile(const std::string& path); static Ptr loadFromMemory(const uint8* data, size_t size); static Ptr loadFromNpk(const std::string& audioPath); ~Sound(); int play(int loops = 0, int channel = -1); int playLoop(int channel = -1); void setVolume(float volume); float getVolume() const; int getLastChannel() const; static void stop(int channel); static void stopAll(); static bool isPlaying(int channel); static void pause(int channel); static void resume(int channel); static void pauseAll(); static void resumeAll(); const std::string& getPath() const { return path_; } private: Sound(Mix_Chunk* chunk, const std::string& path = ""); Mix_Chunk* chunk_ = nullptr; std::string path_; float volume_ = 1.0f; int lastChannel_ = -1; }; }