Initial engine repository
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#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;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user