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 PostsPosition in Mind steve_ancell Wed 20:11 Consumer Lockout steve_ancell Wed 15:24 Professor Oak, Honest!! Afr0 Wed 13:27 Sonic Adventure v0.x Jayenkai Wed 07:08 Coder's Block Jayenkai Wed 06:03 FIRST!!! steve_ancell Wed 03:55 Noel's Graduation waroffice Wed 02:55 Monkey vs iOS tweaks spinal Tue 22:51 Fucking Pound Sign Unicode Bullshit Bollocks Dabz Tue 13:00 Progress / Location Bars dna Tue 08:55 More

 Latest Items News : Newsletter #176Jayenkai Sat 04:49 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
Evil Roy Ferguson
Wed, at 20:21
steve_ancell
Wed, at 20:11
dna
Wed, at 20:01
Afr0
Wed, at 18:04
CodersRule
Wed, at 18:00
Cower
Wed, at 17:22
HoboBen
Wed, at 16:21
Mog
Wed, at 16:17
Dabz
Wed, at 16:03
Jayenkai
Wed, at 15:04