I'm working in a little project and it works basically like a very simple 2d top-down racing game.
In a racing game you have the circuit to follow. With my basic knowledge of hitboxes, I can only think about making the circuit as a flat image, and fill it with circles and boxes of hitbox. Now, this seems rather annoying and timing consuming. There is a better way to do it? I want to basic take a black-white image like that (But of course, with more complex circuits than this):
And make that the white is path to be followed and the black is the hitbox that the objects would interact as a wall.
You can read images, see ImageData:getPixel. If you just want to detect crashes, you can check if any of the four corners is in the black area of an image. For other physics effects like bouncing against the black area, things get more difficult.
pgimeno wrote: ↑Wed Mar 18, 2020 1:29 am
You can read images, see ImageData:getPixel. If you just want to detect crashes, you can check if any of the four corners is in the black area of an image. For other physics effects like bouncing against the black area, things get more difficult.
I see, thanks. ImageData:getPixel may be enough for me right now, I hope.
Since there is a sharp color change between the white and black you write a simple edge detection algorithm and use that to convert the image to edges. You can then use those edges to create polygons. You can preprocess it so that it doesn't have to be done at run time. Once you have the polygons or lines or whatever it ends up being you can then use your favorite collision library.