Latest Uploads Extraterre ... .0.1 (zip)dantheman363Monty Teas ... Screenie 1steve_ancell Santa Clau ... ed his bagwarofficemanic_platdude.pngspinal Tetris Clonesteve_ancellSuper blues bros.spinal
 Code Snippets > Collisions and Physics ( Created 04 April 2012 | Last Edited 04 April 2012)

 Pixel Perfect Collision by melmantheman | No VotesHelps to make pixel perfect(accurate down to a pixel) collisions using image RGB values and Written inJava //this is a method /* * Tells whether or not you can move in the given direction * @param dir the direction you are moving. 0 = up -> clockwise */ public boolean canMove(int dir) { try { if(dir ==0)//up { int clr = collide.getRGB(pX+(bgx*-1)+15,pY+1); if(clr == -65536) return false; } else if(dir == 2)//down { int clr = collide.getRGB(pX+(bgx*-1)+15,pY+30); if(clr == -65536) return false; } else if(dir == 3)//left { int clr = collide.getRGB(pX+(bgx * -1)-1,pY+15); if(clr == -65536) return false; } else if(dir == 1)//right { int clr = collide.getRGB(pX+(bgx * -1)+31,pY+15); if(clr == -65536 ) return false; } } catch(Exception e){e.printStackTrace();} return true; } --> Were as: *collide is image for collision *clr is int value for pixel; *pX is player's x coordinate *bgx is the backgrounds location relative to the player or (0,0) *pY is player's y coordinate How it works: You have a background Image that is a picture of the landscape your going to be playing on, Then you have a near identical picture that is all the collide-able spots on the level colored red. clr is the pixel at the players location (shifted to a side of the player [u/d/l/r]). If that pixel the player is touching is -65536 (the color red) than the player cannot move any further in that direction.

There are no comments for this entry.
 Latest PostseBay Lies spinal Fri 23:44 Shoutbox Topic - 968 dna Fri 19:42 Progress / Location Bars dna Fri 17:25 Development via GUI JL235 Fri 07:59 Meh Afr0 Fri 04:13 Randomly distributed coordinates... Afr0 Fri 00:20 Mog-Dog II : Electric Boogaloo steve_ancell Thu 17:26 Matthew Smith making a comeback?... steve_ancell Thu 03:59 Wrong Partition!!!!? spinal Thu 03:28 Shapes spinal Wed 12:21 More

 Latest Items News : Newsletter #176Jayenkai Fri 04:07 News : Newsletter #175Dabz Tue 09:38 Blog : Snow: More Material JunkCower Sat 23:17 Dev-Diary : Mutant Monty: Amstrad CPC to Windows conversionrockford Fri 13:14 Techy : AppleTVJayenkai Thu 09:40 Blog : Graphvizsteve_ancell Sat 14:17 Pets : Top-Down Shadow HackJayenkai Tue 05:52 Snippet : JNKrunch v1.0Jayenkai Sat 07:20 News : Newsletter #173waroffice Fri 04:47 Blog : Material LoadingCower Fri 02:08 Pets : I Done Won A Thingshroom_monk Sun 11:31 Pets : Repurposing A LexerCower Mon 22:06 Bah : Feeling a Little Angryspinal Mon 11:26 News : Newsletter #170Dabz Sat 00:34 Showcase : sbfgenCower Sat 16:57More

Who's Online
Dabz
Sat, at 01:08
shroom_monk
Sat, at 00:47
Mog
Sat, at 00:18
spinal
Fri, at 23:44
blanko1324
Fri, at 21:51
Cower
Fri, at 21:33
dna
Fri, at 20:39
HoboBen
Fri, at 20:19
CodersRule
Fri, at 18:57