Java - 创建 RPG 对话框
所以这可能看起来很奇怪,但我正在尝试创建一个非常基本的游戏,其工作方式有点像旧的 RPG 游戏可能具有的界面(想想从列表中选择攻击(例如:口袋妖怪))。
现在我有一个扩展 JFrame 的类,它包含三个面板的私有变量:一个用于在屏幕顶部 75% 的位置显示精灵,另外两个是我希望在其上显示文本的面板(一个用于公告)例如,“CRITICAL HIT”和其他可选择的选项)。第二个文本框有时仅可见,但这无关紧要。
有人可以帮助我或帮助我吗?我找到了很多方法,但似乎没有一个能满足我的需求。
编辑:我的游戏已经布局,精灵面板完全按照应有的方式工作,尽管听起来像这样,但我不会盲目地急于做任何事情。除了以有效的方式显示对话框之外,我让游戏正常运行。
编辑2:好吧,也许我不清楚,我基本关心的是找到最好的Java组件来将字符串绘制到底部面板。字符串会定期更改,因此我尝试过的一些方法(例如 Graphics drawString())不是很有效。
谢谢你, 罗夫拉
So this may seem strange, but I am trying to create a very basic game that works somewhat like what an older RPG game may have as the interface (think choosing attacks from a list (ex: Pokemon)).
Right now I have a class that extends JFrame, and it contains private variables of three panels: one for displaying the sprites at the top 75% of the screen, and the other two are the ones I wish to display text on (one for announcements like, "CRITICAL HIT" and the other for the selectable choices). The second of the text boxes would only be visible sometimes, but that is irrelevant.
Can anybody start me off or lend me a hand? I am finding many way but none that seem to work for my needs.
Edit: My game is laid out and the sprite panel works exactly as it should, as much as it may sound like it, I am not rushing into anything blindly. I have the game working except for displaying the dialogs in an effective way.
EDIT 2: Ok maybe I am being unclear, my basic concern is finding the best Java component to draw strings to the bottom panels. The strings will be changing regularly, so some methods that I have tried such as the Graphics drawString() are not very effective.
Thank you,
roflha
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,你最初的问题陈述缺乏任何实际的有凝聚力的问题,除了“有人可以让我开始或帮我一把吗?”这使得弄清楚你真正需要什么变得相当困难。我发现您需要我们帮助的是当某些事件发生时向用户显示弹出的对话框。如果您不太关心特效,可以使用三种简单的方法来做到这一点:
1) 只需为您的消息添加精灵,并根据需要将它们设置为可见。如果您的重要消息数量有限,则可以轻松控制消息的可见性/闪度。
2) JTextArea 允许您简单地将一些文本打印到一个框中。如果您有一个冗长的控制台或消息而不仅仅是几张图像,那么它会很有用。您的面板中只需有一个 JTextArea,并根据需要更新它:
但是用户可能不会注意到文本更改,因为它会立即更改。无论您想要闪烁文本还是在文本区域顶部显示一些动画都取决于您。
3)如果您想要更具侵入性的消息,您实际上可以有一个弹出对话框,用户必须单击“确定”才能继续。这相对容易做到,您甚至可以为消息添加自定义图标:
http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html
Well, your original question statement lacks any actual cohesive question, other than "Can anybody start me off or lend me a hand?" which makes it rather hard to figure out what you really need. I discerned that what you want help from us about is displaying dialogues that popup to the user when some event happens. If you don't care too much about special effects, there are three easy ways to do this:
1) Simply have sprites for your messages, and set them to visible as needed. If you have a limited number of important messages, this makes it easy to control the visibility/flashiness of the message.
2) JTextArea allows you to simply print some text to a box. It is useful if you have a wordy console or messages that can't simply be a few images. You would just have a JTextArea in your panel, and update it as needed:
But the user may not notice when the text changes, since it changes instantly. Whether you want to flash the text, or display some animation on top of the text area is up to you.
3) If you want a more intrusive message, you can actually have a popup dialogue where the user would have to click "OK" to continue. This is relatively easy to do, and you can even put custom icons for the message:
http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html