Re: Collision map
Francois Lionet wrote:
Hello,
For the game I am writing, I need to handle a collision map. This collision
map is a simple array of bits representing an image, a bit set indicating
that there is a collision for this pixel. I am wondering on how to implement
this... I need to be able to scroll this array to follow the scrolling of
the game, to poke a shape into it, and retreive every pixel individually.
The size of this array can be quite big, bigger than the screen.
Should I do it by hand : reserve an array of bytes, and poke the shapes
myself, and do the collision detection. I fear that the scrolling would be
very slow, and that the overall performance would be bad. Is there a utility
class to shift the data in an array by an offset?
Is there any way you can use a base index, so that instead of shifting
data in the array you shift where you are looking? Can you pick a
maximum size during initialization?
If so, you could use an array as a circular buffer, and just adjust the
current base. You could wrap it in a class of your own that automates
mapping from the logical index to the actual index.
Consider using a java.util.BitSet as a circular buffer. It is very space
efficient, packing bits into a long[], 64 bits per element. The size in
bytes would be one eighth of the number of pixels. It already has
methods for setting and clearing blocks of consecutive bits that might
be useful when adding a shape.
If you do end up having to shift the data, rather than adjust the index,
look at System.arraycopy.
Patricia