Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (788) Games in Android Showcase (234) games submitted by our members Games in WIP (862) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Show Posts Pages: [1]
 1 Game Development / Newbie & Debugging Questions / Re: Pixel perfect collision detection? on: 2012-12-14 07:38:09 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.
 2 Game Development / Newbie & Debugging Questions / Re: Pixel perfect collision detection? on: 2012-12-13 22:42:19 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.
 3 Game Development / Newbie & Debugging Questions / Re: Pixel perfect collision detection? on: 2012-12-13 21:46:14 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.htmlhttp://www.java-gaming.org/topics/2d-collision-detection-best-approach/28040/view.html
4  Game Development / Game Mechanics / Re: Perfect collision system (in LWJGL) on: 2012-12-13 08:28:14
Ok, here we are.

 1  2  3  4  5  6  7  8  9  10 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; }

EDIT: It looks like the Rectangle's intersection() method could be useful for only checking the areas in which two locations intersect.
 5 Game Development / Game Mechanics / Re: Perfect collision system (in LWJGL) on: 2012-12-13 08:14:38 Quote from: gouessej on 2012-12-13 08:06:37UnconventionalT, you should rather make the appropriate checks and remove the try/catch clause.You mean something like checking if (k - x) is greater/smaller than a2.length and if (l - y) is greater/smaller than a2[0].length? That wouldn't be necessary if I check only the areas that are overlapping.Also, why? Is this just a bad programming practice?
6  Game Development / Game Mechanics / Re: Perfect collision system (in LWJGL) on: 2012-12-13 07:13:11
The method I'm currently thinking using is to check for basic bounding box collisions (using the Rectangle class and the intersects() method). If it detects a collision, I plan on having it check for pixel-perfect collision. Sometimes I render more than a thousand different bullets, so there won't be a need for pixel-perfect collision detection every update.

The basic idea behind my perfect-pixel collision detection method is to iterate though every pixel in one sprite and check it for every pixel in another sprite. The code then checks the contents to see if both locations contain one opaque pixel. One way to simplify this loop is to return true as soon as a collision is detected. Another method to speed it up would be to only consider the area that the two sprites overlap each other (but I haven't had time to figure that out yet). Another point is that you also have to factor in the offset between the two sprites. Handle any ArrayIndexOutOfBoundsExceptions and throw them away, that just means that the pixels you're checking against don't exist.

Example code using 2 byte[][] arrays. 1 means opaque pixel, 0 means transparent pixel.

 1  2  3  4  5  6  7  8  9  10 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++) {                        try {                            if (a2[k - x][l - y] == 1) { return true; }                        } catch (Exception ex) { } } } } } }    return false; }

(Ignore the terrible formatting, I'm just trying to keep my post length sane.)
 Pages: [1]
 hadezbladez (2129 views) 2018-11-16 13:46:03 hadezbladez (809 views) 2018-11-16 13:41:33 hadezbladez (2102 views) 2018-11-16 13:35:35 hadezbladez (419 views) 2018-11-16 13:32:03 EgonOlsen (3453 views) 2018-06-10 19:43:48 EgonOlsen (3680 views) 2018-06-10 19:43:44 EgonOlsen (2275 views) 2018-06-10 19:43:20 DesertCoockie (3004 views) 2018-05-13 18:23:11 nelsongames (3076 views) 2018-04-24 18:15:36 nelsongames (3853 views) 2018-04-24 18:14:32
 Deployment and Packagingby philfrei2019-02-17 20:25:53Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org