System 模块
主要类型: sf::Time、sf::Clock、sf::Angle、sf::Vector2<T>、sf::Vector3<T>、sf::String、sf::InputStream / FileInputStream / MemoryInputStream、sf::Utf<N>、sf::TimeoutWithPredicate。
- 工厂:
sf::seconds(float)、sf::milliseconds(int32)、sf::microseconds(int64);常量sf::Time::Zero - 读取:
asSeconds()、asMilliseconds()、asMicroseconds()、toDuration();可与std::chrono::duration互转 - 支持
+ - * / %与比较运算
Clock(可暂停)
Section titled “Clock(可暂停)”getElapsedTime()、isRunning()、start()、stop()、restart()、reset()
强类型角度;右手系,窗口 Y 向下时正角为顺时针。
sf::Angle a = sf::degrees(90.f); // 或 sf::radians(...)float d = a.asDegrees();a = a.wrapSigned(); // [-π, π)a = a.wrapUnsigned(); // [0, 2π)using namespace sf::Literals; // 90_deg, 1.57_radVector2 / Vector3
Section titled “Vector2 / Vector3”常用别名:Vector2f / i / u,Vector3f / i,3.1 新增 Vector3u。
成员:x、y(及 z)。Vector2 工具:
| 方法 | 含义 |
|---|---|
Vector2(T r, Angle phi) |
极坐标构造 |
length() / lengthSquared() |
长度 |
normalized() |
单位向量 |
angle() / angleTo(v) |
相对 X 轴 / 相对另一向量的角 |
rotatedBy(Angle) |
旋转 |
projectedOnto(v) / perpendicular() |
投影 / 垂直 |
dot / cross |
点积 / 2D 叉积 Z 分量 |
componentWiseMul / Div |
分量乘除 |
向量运算:+ - * / 与标量。
Rect<T>
Section titled “Rect<T>”- 成员改为
position+size(Vector2),不再有.left/.top/.width/.height与getPosition()/getSize() - 构造:
sf::FloatRect({x,y}, {w,h}) - 相交:
findIntersection→std::optional<Rect>
String
Section titled “String”- Unicode 字符串;可从
const char*、wide、std::string/wstring/u16/u32等构造 - 3.1:接受
std::string_view/wstring_view/u32string_view - 接口侧多用
std::u16string/u32string(相对 2.x)
已移除(改用标准库)
Section titled “已移除(改用标准库)”| 旧 SFML | 替代 |
|---|---|
sf::Thread / Mutex / Lock / ThreadLocal / ThreadLocalPtr |
std::thread / jthread、std::mutex、std::lock_guard、thread_local |
NonCopyable |
= delete |
sf::Int32 等固定宽度整数 |
std::int32_t 等 |