Slick2D 运动问题
因此,我将游戏转换为 Slick2D。机芯坏了,我不知所措。之前,我们使用 KeyPressed 和 keyReleased 方法,但现在使用 Slick2D 移动无法正常工作。
是的,转换到 Slick2D 后一切都不顺利。首先是启动器,我之前有过帮助主题,现在是这个。不过,另一个主题是 WebStart 讨厌代码的问题。
你只能向右移动,使用A。而且你不能停止移动。我使用的方法正确吗?我该如何修复它?非常感谢任何帮助!
这是代码的 PasteBin 链接,如果有帮助的话! http://pastebin.com/GRH86Yuw
So, I converted a game to Slick2D. The movement is broke, and I am at a loss. Before, we used KeyPressed and keyReleased methods, but now with Slick2D movement isn't working right.
Yea, nothing has gone right with converting to Slick2D. First the launcher, which I had a help topic on before, and now this. Though, the other topic was an issue with WebStart hating code.
You can only move right, using A. And you can't stop moving. Am I using the right methods? How can I fix it? Any help is greatly appreciated!
Here is a PasteBin link to the code, if it helps! http://pastebin.com/GRH86Yuw
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是 Slick 的粉丝,我很乐意提供帮助。
根本区别在于,Slick 在输入方面是轮询模型,而不是事件驱动模型。基本上,在逻辑更新方法中,您循环遍历与事件绑定的键,并检查当前是否按下了任何键,然后触发这些事件。如果您愿意的话,我可以向您详细介绍一些原因,轮询对于游戏来说往往效果更好,尤其是在按键数量较多的情况下。这只是一种不同的做事方式,并不复杂。最大的好处是您可以通过单个方法集中输入处理,而不是将其分布在多个 KeyListener 实例对象中。
如果您想查看 Pedestrians - 在 Slick 中实现的简单行人模拟 - 您可以查看一个示例处理 Slick 中的输入。
具体来说,我处理 此文件中的输入(第 192-295 行),在
processInput
方法内。基本上,您传入对 GameContainer 对象(包含游戏的 Slick 对象)的引用,然后您可以从该对象获取 Input 实例的实例,该实例将允许您可以检查按下了哪些键,单击了哪些鼠标按钮等。I'm a fan of Slick, and I'd be happy to help.
The fundamental difference is that Slick is a polling model, not an event-driven model when it comes to input. Basically, in your logic update method you loop through the keys bound to your events, and check to see if any of the keys are currently pressed, and then trigger those events. For a number of reasons that I can go into if you like, polling tends to work better for games, especially with a large number of keys. It's just a different way of doing things, an not that complicated. The biggest upside is that you get centralized input processing a single method, instead of having it spread across multiple KeyListener instance objects.
If you want to look at Pedestrians - a simple pedestrian sim implemented in Slick - you can see an example of how to handle input in Slick.
Specifically, I handle input in this file (lines 192-295), inside the
processInput
method. Basically, you pass in a reference to theGameContainer
object (the Slick object that contains your game), and from that you can get an instance to theInput
instance that will allow you to check which keys are pressed, what mouse buttons are clicked, etc.