Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (565) Games in Android Showcase (151) games submitted by our members Games in WIP (606) 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]
 theagentd (11 views) 2015-03-27 23:08:20 wxwsk8er (52 views) 2015-03-20 15:39:46 Fairy Tailz (46 views) 2015-03-15 21:52:20 Olo (28 views) 2015-03-13 17:51:59 Olo (30 views) 2015-03-13 17:50:51 Olo (38 views) 2015-03-13 17:50:16 Olo (44 views) 2015-03-13 17:47:07 ClaasJG (57 views) 2015-03-10 11:36:42 ClaasJG (41 views) 2015-03-10 11:33:01 Pippogeek (48 views) 2015-03-05 14:36:23
 BurntPizza 21x LiquidNitrogen 21x basil_ 20x KevinWorkman 18x EgonOlsen 17x theagentd 16x Roquen 16x 65K 11x wessles 10x Varkas 10x Riven 10x princec 9x phu004 8x SHC 8x Ashedragon 8x lcass 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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