迁移指南
从 SFML 2 或 3.0 升到 3.1 时,下列变更最容易踩坑。完整清单见官方 2→3 与 3.0→3.1 迁移页,以及源码 migration.md。
SFML 2 → 3 迁移陷阱
Section titled “SFML 2 → 3 迁移陷阱”- C++17 + 新 CMake 目标名(
SFML::Graphics,组件首字母大写)。 - 所有
(x,y)参数 →Vector2:setPosition({x,y})、VideoMode({w,h})、IntRect({x,y},{w,h})。 - Event 全面重写:无
event.type/event.key;用optional+is/getIf或handleEvents。 - Angle:
setRotation(sf::degrees(90)),读角.asDegrees()。 - Scoped enums:
Keyboard::Key::A、Mouse::Button::Left、PrimitiveType::Triangles… - Rect:
.position/.size;findIntersection。 - 无默认构造:
Sprite(texture)、Text(font)、Sound(buffer)。 - 资源构造即加载,失败抛
sf::Exception;旧式loadFromFile/openFromFile仍可用。 - 重命名: Font
openFromFile;Texture / Image / RenderTextureresize;SoundsetLooping;getNativeHandle;antiAliasing。 - 删除: 线程原语、
NonCopyable、View::reset、Vertex构造、Text::setColor、Shader::setParameter、RenderWindow::capture、PrimitiveType::Quads、旧 MouseWheel 事件等。 - Fullscreen:用
sf::State::Fullscreen,不再靠Style::Fullscreen。 - RenderStates 增加
CoordinateType(及 StencilMode 等)成员。 - 音频 Channel Map 改
loadFromSamples等签名。 - Clipboard / Keyboard / … 是 namespace 不是类。
3.0 → 3.1 要点
Section titled “3.0 → 3.1 要点”- 文本塑形 / BiDi / 竖排 / GlyphPreProcessor;弃用
findCharacterPos。 Dns替代IpAddress::resolve;Sftp替代Ftp;Http HTTPS;SocketSelector 回调。- QOI 图像;
Vector3u;String的 string_view;PlaybackDevice::getDeviceSampleRate。 - Touch 实时 API 弃用。