Using FlxCollision.pixelPerfectCheck with atlas sprites

50 views
Skip to first unread message

Andyba

unread,
Jul 9, 2015, 6:19:08 AM7/9/15
to haxef...@googlegroups.com
I am working on a fighting game where sprites are quite large and they use texture packer data.

I get slowdowns when testing for overlaps with FlxCollision.pixelPerfectCheck and I noticed that it is not optimized for atlas sprites.

Before checking for pixel collisions It first checks if the bounds of the sprite collide instead of checking the bounds of the atlas frame.

So when it calculates the rectangle intersection it is usually much larger than necessary and in my case has to loop more often through 3 times more pixels to find the collision.
The atlas frame can be much smaller than the sprite bounds and usually there are no nontransparent pixels outside of it.

I have started writing a new collision class based on FlxCollision.pixelPerfectCheck but I am wondering if there are better solutions.

Thank you.





SruloArt

unread,
Jul 9, 2015, 8:37:03 AM7/9/15
to haxef...@googlegroups.com
Wait, this happens with the dev branch or with a regular release?

Andyba

unread,
Aug 3, 2015, 8:26:08 AM8/3/15
to HaxeFlixel
I've looked through the FlxCollision.pixelPerfectCheck code in Dev branch and haven't seen anything substantially different from regular release.
So if you have a sprite that has large regions of empty space to allow some animation freedom, it will use all that empty region when calculating collisions.

I have created my own class that uses the atlas frame data to detect the bounding box collision which works quite well. 
But I didn't figure out how to make it work with rotated sprites.

SruloArt

unread,
Aug 9, 2015, 3:50:48 PM8/9/15
to HaxeFlixel
I've asked because the dev branch has a very different implementation for frames in general and (Flx)Atlas in particular...
Reply all
Reply to author
Forward
0 new messages