SDL.NET (VB/C#):启动对象和应用程序类型应该是什么?

发布于 2024-08-03 03:22:37 字数 1047 浏览 3 评论 0原文

由于 VB.NET 的各种缺点(糟糕的音频支持、执行过程中没有读取事件、键盘输入非常弱等),我最终无法进一步开发我的程序。所以我尝试了 SDL.NET 6.1。
尽管它的文档很糟糕,但我能够修复我的代码来使用它,我喜欢它!

但有一个问题。我不知道如何为其设置我的应用程序设置。启动对象绝对应该是一个类(示例总是在类中,而不是模块中),但是启动类必须是一个表单!这很糟糕,因为 SDL 通过 SetVideoMode 创建自己的窗口;你不需要表格。因此,当表单构造函数 New() 完成时,创建了一个无用的表单,并且您有两个窗口。

我尝试在 New() 中调用游戏引擎循环,以便游戏在没有 New 的情况下启动() 永远完成。游戏正常运行,这解决了“第二个窗口”问题...但无法关闭! X 按钮不执行任何操作,对 Events.QuitApplication 或 Me.Close 的调用被公然忽略,等等,

我很困惑。看来我需要设置一个非表单类作为启动对象,但它不允许我这样做。

哦,对了,好像有两个东西叫“SDL NET”。为了澄清,我正在使用 这个,它存在于 SdlDotNet 命名空间。

哦,我忘了提,我还注意到很多示例都有一行写着“[STAThread]”。这很重要吗?

编辑: 我已经收到并接受了我的问题的答案,但我想告诉其他人退出/关闭应用程序的问题是什么,即使这不是我的问题:
虽然 SDL.NET 允许您在不必停止运行逻辑的情况下接收输入并运行其他事件,但在逻辑运行时应用程序仍然无法退出。因此,我发现告诉 SDL.NET 应用程序在运行逻辑中间退出的最佳方法是使用以下两行:

SdlDotNet.Core.Events.QuitApplication
End

将它们放在 SdlDotNet.Core.Events.Quit 事件的处理程序中以及其他任何地方你希望你的程序退出。

I eventually couldn't get any further with my program due to the various shortcomings of VB.NET (bad audio support, no reading events in the middle of execution, very weak keyboard input, etc). So I tried SDL.NET 6.1.
Despite its terrible documentation, I was able to fix my code to use it and I love it!

But there's a problem. I don't know how to set up my application settings for it. The Startup Object definitely should be a class (the examples always are in classes, never modules), but a startup class specifically has to be a form! This is bad because SDL makes its own window via SetVideoMode; you don't need a form. So when the form constructor New() finishes, a useless form is created and you have two windows.

I tried placing a call to the game engine loop within New() so that the game starts up without New() ever finishing. The game runs normally, and this solves the "second window" problem... but it can't be closed! X button does nothing, calls to Events.QuitApplication or Me.Close are blatantly ignored, etc.

I'm stumped. It seems I need to set a non-form class as the startup object, but it won't let me.

Oh, by the way, it seems that there are two things called "SDL NET". To clarify, I'm using this one, which exists in the SdlDotNet namespace.

Oh, I forgot to mention, I also noticed that a lot of the examples have a line that says "[STAThread]". Is this is important?

EDIT:
I've already received and accepted an answer for my question, but I want to tell other people what the problem is with exiting/closing the app, even though that wasn't my question:
While SDL.NET allows you to receive input and run other events without having to stop running logic, the application still cannot quit while logic is being run. So I find the best way to tell your SDL.NET application to Quit in the middle of running logic is to use the following TWO lines:

SdlDotNet.Core.Events.QuitApplication
End

Place these in the handler for the SdlDotNet.Core.Events.Quit event, as well as anywhere else you want your program to quit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2024-08-10 03:22:37

启动对象绝对应该是一个类(示例始终位于类中,而不是模块中)

这是您的错误。从 CLR 的角度来看,类和 VB 模块之间没有真正的区别。因此,只需将其作为 Main 的模块即可,然后继续。不需要上课。我怀疑您正在查看使用类的 C# 示例 - 但那是因为 C# 中不存在模块之类的东西。

[STAThread] 可能不会对 SDL 产生任何影响。它对于 UI 应用程序很重要(WinForms 和 WPF 都需要它),但我不认为 SDL 执行任何 COM 调用,因此它不应该关心您的线程是否 STA 与否。它只是 Visual Studio 默认放在新项目中的 Main 上的内容。

The Startup Object definitely should be a class (the examples always are in classes, never modules)

Here's your mistake. There's no real difference between a class and a VB module from CLR perspective. So just make it a module with Main and go on. There is no need for a class. I suspect you're looking at C# examples, which use classes - but that's because there is no such thing as a module in C#.

[STAThread] probably won't make any difference for SDL. It is important for UI applications (both WinForms and WPF require it), but I don't think that SDL does any COM calls, so it shouldn't care whether your thread is STA or not. It's just something that Visual Studio puts on Main in new projects by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文