• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Glak

[java] java2D and swing

7 posts in this topic

I was wondering how the two work together. I''m making a multiplayer turn based strategy game. The basic turn structure is as follows: input: player can scroll around map and enter commands, player can send and recieve messages in the text part of the interface input synch: all commands entered are sent to other players action: there will be 61 action phases, the interface is disabled, things are completely automated based on players input So I was wondering how it works, do I make a JFrame and then designate parts of it to work with java 2D and have the rest swing? or is the whole thing java2d and I just throw swing parts on and try not to draw over them?
0

Share this post


Link to post
Share on other sites
I would do it like this:
JFrame: GUI, takes in all key-inputs and makes them happen.
Canvas/JPanel: All graphics here, handles some mouse clicks targetted to the game like targetting enemy vehicle or recieving info.


I don''t know what do you mean by:

...designate parts of it to work with java 2D and have the rest swing? or is the whole thing java2d and I just throw swing parts on and try not to draw over them...

If you draw everything on Canvas you don''t have to take care of other components. I mean you can just layout them with null-layout or borderlayout and handle their events.

Time comes, time goes and I only am.
0

Share this post


Link to post
Share on other sites
Make sure you use JPanel and not Canvas though. I had horrible problems with JMenus and other Swing stuff until I found something on Sun''s website telling me not to mix Swing and AWT components.

Neil
0

Share this post


Link to post
Share on other sites
Java2D is not really separate from AWT or Swing. AWT is the (older) heavyweight graphics model, Swing is the (newer) lightweight graphics model, and Java2D is the new Graphics wrapper that allows you to use new functions with either. A big no-no is to mix heavyweight and lightweight components. This means if you use AWT you should avoid Swing components and vice-versa. Another heavyweight API is the Java3D API, so using Java3D with Swing is difficult at best.

One thing to consider is that if you are using Java2D and/or Swing, you are locking yourself into the Java2 environment. This means your program will not run in a typical browser without the Java Plugin (or modification to the browser). If you are deploying an application with a runtime evironment, this isn''t a problem, just distribute the 1.2.2 or 1.3 environment. If you are planning an applet distro, this will force your players to download the Java Plugin before they can play. This may be unacceptable, which will jam you into AWT and 1.1

If you do wind up using Java2D and Swing, check out the the following classes:
JLayeredPane: this is a panel that supports layered graphics.
JViewport: a viewport class for virtual panning (scrolling)
JComponent: The base item for any Swing component. Good to subclass for your own items. (Arguably better than JPanel...but it is ultimately your descision.)
BufferedImage: The cornerstone of Java2D, an image stored in memory
ImageIcon: A quick and dirty way to get JPGs and PNGs into the BufferedImage class.
AffineTransform: Java2D class for rotation, translation, skew, scale, good stuff.

I could go on and on (but won''t), if you need more to get started, drop me an email.

ManaSink@hotmail.com
0

Share this post


Link to post
Share on other sites
Thanks everyone. I suppose I was kind of vague. From the answers it seems that I''ll need two areas that are BufferedImages, one for the main map and one for the minimap, and then I''ll just make another part to hold the swing components. So it sounds like I need a JFrame to be the whole game window, then I''ll need to add some sort of canvas-like (but not canvas) place for my main map, which I''ll use to send BufferedImages to. I''ll need basically the same thing for the minimap. Then I''ll have another swing thing that holds all of the swing components. The swing parts should basically be responsible for drawing themselves but I''ll be the one who decides what the main and minimaps show. Ok thanks, oh and I plan on making an .exe out of it (I already figured that out, whoohoo) so I shouldn''t have that problem, at least not for a while.
0

Share this post


Link to post
Share on other sites
A lot of this is basic stuff that I haven''t seen anywhere game related(like panning using a JViewport). Perhaps a Java specific game tutorial is in order. I''d love to put together something, as it would give me a chance to get back into the ''swing'' of things (grin) and would help a lot of others out.

Hmmmm....

Any comments?

ManaSink
0

Share this post


Link to post
Share on other sites
I read about that viewport thing and some of the other classes. Apparently the viewport only lets you have one object, the reason must be to make it more flexible, the one object can be a container that can hold lots of objects. Does the viewport do scrolling on its own? (like in an RTS) or do you have to make it work yourself? If it does it on its own then how do you set the scroll speed? If it doesn''t then what is the point of a viewport?

Assuming that I use a viewport, would this be a good way to do things: I make the one item a container, maybe a JPanel or something like that and it holds all the squares. Then each of my map tiles would be a subclass of some swing component that I could draw on. So the viewport would only call the paint method for those squares that would be on the screen, and it doesn''t bother drawing the rest of the squares. The squares will need custom drawing methods because the stuff on the squares won''t exactly have paint methods. Oh and since the squares themselves would be swing components that might make some of the interface easier.

Oh and yes a tutorial would be very nice.
0

Share this post


Link to post
Share on other sites
Glak-
I would suggest the following for starters:

Your game tiles extend JComponent, overriding paintComponent() to paint themselves. Often they will just draw a buffered image onto the graphics context. If their state changes, they can paint themselves differently (animated tiles, tiles that can be damaged, etc.)

Create a JPanel instance that uses a grid layout with no horizontal or vertical gap. You can also set the layout to null and just specify the tile locations manually. Add instances of all the tiles. You now have a large panel that holds your map. It may be bigger than the screen because you will use a viewport to view its contents.

Create an instance of JViewport, setting the size of your viewport. This will be smaller than your map (JPanel). Set the JPanel created above as the View with setView(). To move the extent that the viewport is windowed on, call setViewPosition() with the point you''d like to move to (in the JPanel''s coordinate system).

Does it scroll itself? I''m not sure I understand the question, but it is easy to set it up to scroll however you''d like. Track the mouse and update the position based on what edge the mouse is on, tie scrolling to the arrow keys, fix the viewport on a moving sprite, etc. Just call setViewPosition when you want it to move.

You can also use multiple JViewport instances with JLayeredPane to create layers of graphics that you can scroll individually. This is great for parallax scrolling, fixing your main sprite in the center, drawing your UI over everything else, etc..

The actual code that you created here was just your custom tile and whatever main class is setting it all up, everything else is standard Swing. As a result, your deliverabe code is very small, which is good if it will be downloaded over the net, and you get to reap the performance benefits of any enhancements to the Swing package (from 1.2 to the new 1.3 for example). Plus the simplification of being able to focus on coding gameplay rather than reinventing the ''2D scroller wheel''...

I''ll start some leg-work on the tutorial, if you have any requests / ideas , post em up.

ManaSink
0

Share this post


Link to post
Share on other sites