如何编辑 SFML 源代码以添加新的可绘制对象?
嘿,我正在开发一个名为“Body”的类,它将形状和精灵作为一个对象保存在一起。我想进入源代码并添加一个新的重载RenderWindow的Draw()函数,以便可以轻松地接收和绘制这个新对象。 我该怎么做?
我目前使用的是
- Windows 7
- SFML 1.6
- 新的 msVS++ 2010 编译的静态调试库和 dll
- 原始包含文件夹
编辑:
我还在 Drawable.hpp 标头中找到了这个:
private :
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// Draw the object into the specified window
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
void Draw(RenderTarget& Target) const;
////////////////////////////////////////////////////////////
/// Render the specific geometry of the object
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const = 0;
但我可以不知道每个函数的完整代码在哪里,只知道声明。 不幸的是,我也没有在那里找到迷你教程......
Hey i'm working on a class called a "Body" which holds shapes and sprites together as one object. I would like to get into the source code and add a new overload RenderWindow's Draw() function, so this new object can be taken in and drawn easily. How do i do this?
I'm currently using
- Windows 7
- SFML 1.6
- Newly msVS++ 2010 compiled static debug libraries and dlls
- original include folder
EDIT:
I also found this in the Drawable.hpp header:
private :
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// Draw the object into the specified window
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
void Draw(RenderTarget& Target) const;
////////////////////////////////////////////////////////////
/// Render the specific geometry of the object
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const = 0;
but i can't figure out where the full code of each function is, just the declarations.
I didn't find a mini tutorial there either unfortunately...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:
在派生并实现自己的 Drawable 之前,您可能需要考虑是否需要这样做。 SFML 的作者声明
sf::Drawable
最初并不打算在 SFML 之外进行子类化。除此之外,
对于 SFML 1.6:
看来您所需要做的就是从
sf::Drawable
派生类,然后实现虚拟Render函数。
在 SFML 论坛上可以找到这样的示例 。
对于 SFML 2.0:
< SFML 中的 code>Drawable 头文件包含描述如何派生您自己的
Drawable
类的注释。您无需修改 SFML 源代码即可创建新的 Drawable。它还包括一个简单的示例:
此示例可能适用于 SFML 2.0,但如果您从任何版本的 SFML 检查
Drawable.hpp
,它都应该包含类似的示例。Note:
Before you derive from and implemented your own Drawable, you may want to consider if you need to do it at all. The author of SFML has stated that
sf::Drawable
was not initially meant to be subclassed outside of SFML.That aside,
For SFML 1.6:
It appears that all you need to do is derive your class from
sf::Drawable
, and then implement a virtualRender
function.An example of this can be found on the SFML forums.
For SFML 2.0:
The
Drawable
header file from SFML contains comments that describe how to derive your ownDrawable
classes. You do not need to modify the SFML source code to create new Drawables.It also includes a simple example:
This example may apply to SFML 2.0, but if you inspect the
Drawable.hpp
from whatever version of SFML you have it should contain a similar example.RenderWindow::Draw
采用抽象类类型Drawable
的对象。这意味着,理论上,您可以将您的Body
类作为Drawable
的子类,并重载一些虚拟方法以使其呈现。但事实似乎并非如此。
Drawable
的文档显示只有该类中有一个虚函数:析构函数。这……有点愚蠢。然而,外表可能具有欺骗性。我正在检查2.0文档,看看他们是否已经弄清楚如何正确地创建继承层次结构,结果证明它们确实有要重写的虚拟方法。只是它们都是私有的(这本身很好,实际上是一件非常好的事情),并且 SFML 人员没有告诉 Doxygen 为私有成员生成文档。我就此向他们提交了一个错误。
在他们更新文档之前,我唯一能说的就是查看标头,也许还有 Sprite 的源代码,并尝试找出如何正确创建派生的 Drawable 类。
RenderWindow::Draw
takes an object of the abstract class typeDrawable
. Which means that, in theory, you can just make yourBody
class a child ofDrawable
and overload some virtual methods to make it render.But that doesn't seem to be the case. The docs for
Drawable
show that there's only one virtual function in that class: the destructor. Which is... kinda stupid.However, looks can be deceiving. I was checking the 2.0 documentation to see if they had figured out how to make an inheritance hierarchy correctly, and it turns out that they do have virtual methods to override. It's just that they're all private (which itself is fine, and in fact a very good thing), and the SFML guys didn't tell Doxygen to generate documentation for private members. I filed a bug with them on this.
Until they update their docs, the only thing I can say is to look at the header, and maybe the source code to Sprite, and try to figure out how to create a derived Drawable class correctly.