Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Some thoughts on your approaches</strong></p> <p>The first approach will probably perform better, because you could just use a single VolatileImage for the whole drawing. However, you're right about it being more complicated than the second approach, because you will have to handle all the layering yourself.</p> <p>The second approach is nice not just for the reasons you've state, but because if you need to do anything like handle when a mouse enters a specific "sprite" on the screen, that is given to you automatically by Java's JPanel implementation. That said... Space Invaders clones are typically controlled by the keyboard, so whether or not you actually use this functionality is another story entirely.</p> <p>Bottom line... I usually end up doing this kind of stuff in the <code>paint()</code> paradigm. Layering the paint is not that hard at all, especially for something as simple as Space Invaders, and it will make improving performance easier if you decide to use <code>VolatileImage</code> as your back buffer.</p> <p><strong>Other thoughts</strong></p> <p>As others have said, it's tough to get consistent "frame rates" in swing because you have no control over "when" something gets rendered - that is determined by the EDT, which runs asynchronously with respect to your code. If you decide to rely on the EDT, you might try using a <code>SwingTimer</code> for your rendering. Be extra careful to synchronize your rendering and updates to the underlying game state properly as well.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload