简体   繁体   English

Java-创建RPG对话框

[英]Java - Creating an RPG dialog

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)). 因此,这似乎有些奇怪,但是我试图创建一个非常基本的游戏,其工作方式与旧版RPG游戏的界面类似(请考虑从列表中选择攻击(例如: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). 现在,我有一个扩展JFrame的类,它包含三个面板的私有变量:一个用于在屏幕的顶部75%处显示精灵,另外两个是我希望在其上显示文本的(一个用于公告)例如“ CRITICAL HIT”,另一个则是可选选项)。 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. 编辑2:好的,也许我不清楚,我的基本担心是找到最好的Java组件以将字符串绘制到底部面板。 The strings will be changing regularly, so some methods that I have tried such as the Graphics drawString() are not very effective. 字符串将定期更改,因此我尝试过的某些方法(例如Graphics drawString())不是很有效。

Thank you, roflha 谢谢你

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. 1)只需为您的消息添加精灵,然后根据需要将其设置为可见。 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. 2)JTextArea允许您简单地将一些文本打印到框中。 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: 您只需在面板中有一个JTextArea,然后根据需要对其进行更新:

JTextArea messageBox;
messagePanel.add(messageBox);

//displays a message
messageBox.setText("CRITICAL HIT!!!");

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. 3)如果您想要更具侵入性的消息,则实际上可以有一个弹出对话框,用户必须单击“确定”才能继续。 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 http://download.oracle.com/javase/tutorial/uiswing/components/dialog.html

JOptionPane.showMessageDialog(myFrame,
    "You got a critical hit!!!", 
    "Critical Hit",
    JOptionPane.INFORMATION_MESSAGE,
    criticalHitIcon);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM