Best practice for creating composite images for Java Swing

Im is working on a 2d game in java swing, where the procedure-created environment is represented by a tiled array of low-resolution images. This is currently all in html tags (for line breaks) in JLabel.

In addition, I would like to display character sprites that will not process the entire slab, but will have some alpha components. Previously, in JS / html and JS / canvas, I simply made sketches with alpha channels and positioned them directly above the floor tiles using tables and / or absolute positioning.

In java swing, however, absolute positioning (and most of the html for that matter) does not seem to work so well.

Since the sprite will never be between / overlapping double-decker slabs, the obvious solution is to create a bunch of precomputed image files outside the game - one for each character on each type of floor tile, however this (and work) exponentially with the number of images used and it seems not necessary.

From what I saw, it seems like it should be possible to create all these images at runtime in the form of Bufferedimages, either by pre-computing them at startup, or by creating each frame if necessary.

If I can do this, I can also put all the images that I need into one large raster file of each frame and display it. It can also reduce unsynchronized frame loading if I overload the system.

From the options above, what seems the best? Or is there another obvious solution that I completely lost? If the solution is to create composite images, can someone point me in the right direction how to do this? Many thanks.

+1
source share
1 answer

An entire book will be taken in this section, but essentially what you can do ...

Create a custom component (expanding from JPanelor an example) that is used to visualize the world, how much this renderer will depend on your needs, but you can display only a small subset of the whole world, This is important because if you did not display it, you don’t want to display it.

paintComponent .

png , , Graphics#drawImage. , , "" , , , , .

, paintComponent, , , , , paintComponent, .

...

. , , .

+1

All Articles