This is something i need for my game as collision detection is not as accurtate as it needs to be… so, do you guys have any idea how to do this? I do not … :’(
2 topics alone on the first page of the Game Mechanics board.
http://www.java-gaming.org/topics/perfect-colision-system-in-lwjgl/27836/view.html
Im not using the LWJGL since im on android
and the other one does not have an actual answer
There are many different solutions suited for many different situations. Could you link to a screenshot explaining what you’re dealing with?
There’s the brute force method, but it is rarely good on its own. Then you’d use quad-trees as a broad-phase tester.
But if you have a simple platformer, you could make do with bitmasks, or even just have an array of ints representing the y-height of each x-width in each ground-tile.
how do i post images? i only see an option by linking it to a website
The first link has a post (by yours truly) at the bottom of the thread detailing how one goes about implementing pixel-perfect collision. The second link contains a simple method for basic collision detection in games. The basics behind 2D pixel-perfect collision detection methods don’t exactly change from engine to engine.
Ok so after reviewing your thread i noticed this code
public static boolean intersectsByte(byte[][] a1, byte[][] a2, int x, int y) {
for (int i = 0; i < a1.length; i++) {
for (int j = 0; j < a1[0].length; j++) {
if (a1[i][j] == 1) {
for (int k = 0; k < a1.length; k++) {
for (int l = 0; l < a1[0].length; l++) {
if (((k - x) >= 0) && ((k - x) < a2.length) && ((l - y) >= 0) && ((l - y) < a2[0].length)) {
if (a2[k - x][l - y] == 1) {
return true; } } } } } } }
return false; }
I need some help understanding this however. If i already have two bitmaps setup how to I use this code to detect pixel perfect collision.?
One method that would work would be to simply convert both of your images to byte[][] arrays, where 1 represents an opaque pixel and 0 represents a transparent pixel. That may not be the best method, though.