如何在运行时制作动态图像?
我正在开发一款基于 NetBeans 平台的纸牌游戏,并且正在努力理解动态图像。为什么是动态的?好吧,我希望卡片在运行时根据页面的更改(即名称、文本、成本等)进行调整。
我的第一个破解是创建一个组件(JPanel),其中预先放置了标签,我根据卡值加载文本/图像。这似乎工作得很好,但当我想到某些页面在以后的版本中具有不同的外观(意味着并非所有内容都在同一个地方)时,它就变得很麻烦。
所以我试图了解如何基于某种模板来做到这一点。
有什么想法吗?
有一个后续问题:JList of cards?
I'm working on a card game based on the NetBeans platform and I'm struggling to get my head around dynamic images. Why dynamic? Well I want the cards to adjust at run time to changes to the page (i.e. name, text, cost, etc).
My first hack at it was creating a component (JPanel) with labels pre-placed where I loaded the text/image based on the card values. That seems to work fine but then it became troublesome when I thought about some pages having a different look in later editions (meaning not everything would be on the same place).
So I'm trying to get an idea about ways to do this based on some kind of template.
Any idea?
There's a follow-up question at: JList of cards?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我有时间回到这个问题,并能够找到一种使用 Java 2D 教程。
这些图片与我将在应用程序中使用的图片并不接近,但可以作为概念证明。
它仍然需要一些改进,特别是在文本的位置上,但它是有效的。我想我可以实现一个 xml 格式来存储所有这些信息,这样就可以轻松配置。在下面的示例中,太阳被绘制在雨的顶部,文本位于所有这些的顶部。对于我的应用程序,每一层将一起构建我想要的页面。
这是我使用的图像:
最终结果:
Finally I got some time to get back to this and was able to figure out a way using Java 2D tutorial.
The pictures are not near what I will use in my application but serves as proof of concept.
It still needs some refining specially on the placement of the text but it works. I guess I can implement a xml format to store all this information so is easily configurable. In the example below suns are drawn on top of rain, and the text is on top of all that. For my application each layer will build together the page I want.
Here are the images I used:
And the final result: