Author Topic: Pixel Perfect Colliding with Power Tools  (Read 3264 times)

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Pixel Perfect Colliding with Power Tools
« on: Sat, Jan 7, 2012 »
Hey all!
I can't figure out out to do pixel perfect colliding with PhotonStorm's Power tools. Here's my code:
Code: [Select]

if(FlxCollision.pixelPerfectCheck(player,map) == true) {
FlxObject.separate(map,player);
}
Thanks in advance.   8)

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Pixel Perfect Colliding with Power Tools
« Reply #1 on: Sun, Jan 8, 2012 »
I really would like a reply to this.... :D

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Pixel Perfect Colliding with Power Tools
« Reply #2 on: Sun, Jan 8, 2012 »
Ok I see the code but you don't say what the problem is  :P

Would also help to see a screenshot of the things you're trying to collide.

Did you try the demo included in the power tools? Start by copying it and then replace his objects with yours should give you a better idea of what the problem is. You can also turn on the debug view like he does in the top-left corner to see what the code sees.

I don't think FlxObject.separate will work well with pixel perfect collision because it uses Flixel's bounding boxes, so you would be checking collision against pixels, but then separating against bounding boxes. But I never tried it so I'm not 100% sure.

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Pixel Perfect Colliding with Power Tools
« Reply #3 on: Sun, Jan 8, 2012 »
Yeah somehow I need to make it so it figures which way to push out until your not pixel perfect colliding...

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: Pixel Perfect Colliding with Power Tools
« Reply #4 on: Mon, Jan 9, 2012 »
It looks to me like you're trying to collide a sprite with a tile map, which won't work. Is that the case?
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Pixel Perfect Colliding with Power Tools
« Reply #5 on: Mon, Jan 9, 2012 »
No, a single sprite.

Leone Simonetti

  • Member
  • **
  • Posts: 16
  • Karma: +0/-0
    • View Profile
Re: Pixel Perfect Colliding with Power Tools
« Reply #6 on: Fri, Jan 13, 2012 »
Well. i don't think you have to put that "==true"
do you remember to import the class? : P

camasthecat

  • Contributor
  • ****
  • Posts: 461
  • Karma: +0/-0
  • WOW! 400+ Posts!? Jeez! Do I have a life!?!?
    • View Profile
    • My site for thermalJS, an HTML5/Javascript engine kinda-like flixel:
Re: Pixel Perfect Colliding with Power Tools
« Reply #7 on: Sat, Jan 14, 2012 »
Yeah I know I don't have to do that, because it returns a value. (In this case, a Boolean) But it didn't work, so I just added "==true"
I understand the reason, but I wonder how I can do this. Somehow I need to figure out the side I'm colliding on, and then push him out. Maybe FlxG.seperate's code could help?

datorum

  • Active Member
  • ***
  • Posts: 165
  • Karma: +0/-0
    • View Profile
Re: Pixel Perfect Colliding with Power Tools
« Reply #8 on: Wed, May 23, 2012 »
I have exactly the same problem! Do you figured out a solution?

The situation is simple:
if you use FlxG.collide(terrain, sprite) the sprite can't pass through the terrain. BUT bounding boxes are used. (Note: terrain is also a FlxSprite in my case)

Since we want pixelperfect collision in order to get a sprite "moving" on the pixels of the terrain (and not it's bounding box),
we used the pixelperfect collision check (provided by PowerTools) and then apply the same code that is withing collide().
To our understanding this is separate(), but it simply doesn't work. :(

Code: [Select]

static public function collide(ObjectOrGroup1:FlxBasic=null, ObjectOrGroup2:FlxBasic=null, NotifyCallback:Function=null):Boolean
{
return overlap(ObjectOrGroup1,ObjectOrGroup2,NotifyCallback,FlxObject.separate);
}

For some reason the separate code doesn't work in this context, does anyone know why or how to fix this problem?
« Last Edit: Wed, May 23, 2012 by datorum »