BPM
在本章中,您将会学习到:
- BPM 变化原型
- 绘制 BPM 变化刻度线
BPM 变化
在游玩模式中,我们不需要实现 BPM 变化原型,因为 BPM 变化会被相关函数自动处理,我们不需要对其坐任何事。
然而在预览模式中,我们想要通过将其打印到一边来显示 BPM 何时变化以及变化后的值。
BPM 变化原型
让我们先设置一个 BPM 变化原型:
class BpmChange: public Archetype {
public:
static constexpr const char* name = "#BPM_CHANGE";
};
// ...
#ifdef preview
using namespace previewData;
#include"preview/Initialization.cpp"
#include"preview/Stage.cpp"
#include"preview/Note.cpp"
+ #include"preview/BpmChange.cpp"
#elif watch
// ...
// ...
#ifdef preview
buffer data, configuration;
build<
// Replace with your archetypes here
Initialization,
Stage,
Note,
+ BpmChange
>(configuration, data);
// ...
数据
我们想要通过 Entity Data 区块来访问 BPM 变化的节拍和 BPM 值。由于 C++ 不支持 #
开头的变量,我们只能手动添加数据:
class BpmChange: public Archetype {
// ...
vector<pair<string, int> > imports = {
{ "#BEAT", 0 },
{ "#BPM", 1 }
};
Variable<EntityDataId> beat(0, true);
Variable<EntityDataId> bpm(1, true);
};
声明
class Sprites {
public:
// ...
int bpmChangeLine = 6;
}Sprites;
auto skins = defineSkins<class Sprites>({
// ...
{ SkinSpriteName.GridPurple, Sprites.bpmChangeLine }
});
打印与刻度线
现在我们可以打印 BPM 值并绘制刻度线:
class BpmChange: public Archetype {
// ...
SonolusApi render() {
FUNCBEGIN
line(Sprites.bpmChangeLine, beat, 0.5);
print(bpm, BeatToTime(beat), PrintFormat.BPM, -1, PrintColor.Purple, false);
return VOID;
}
};