Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection fails on scaleX = -1 #4

Open
Cosmitar opened this issue Jan 25, 2014 · 2 comments
Open

Detection fails on scaleX = -1 #4

Cosmitar opened this issue Jan 25, 2014 · 2 comments
Assignees

Comments

@Cosmitar
Copy link

Hi, im testing this great library playing with some sprites and I found that no collision is detected when I reflect the sprite with scaleX = -1
To solve and check this, I save and restore scaleX when it is = -1

var scaleX = mySprite.scaleX; //save
if( mySprite.scaleX == -1 ){ mySprite.scaleX = 1; } //fix
collision = ndgmr.checkPixelCollision( someSprite, mySprite );
mySprite.scaleX = scaleX; //restore

I guess this is a bug.
Hope this help!

@olsn
Copy link
Owner

olsn commented Jan 26, 2014

Hi,
I cannot say currently when I will have the time to look into this, but I have noted it for now and will take a look at it as soon as possible.

@ghost ghost assigned olsn Jan 26, 2014
@martialc
Copy link

It also fails on scaleY = -1.

Which becomes quite a bigger problem with the quick fix above (collisions are detected as if the object was not vertically scaled, which is the point of the patch, but gives wrong collision coordinates).

Another quickfix, with better results :

In _collisionDistancePrecheck = function(bitmap1,bitmap2) :

Change the return value to:

return(Math.abs(b2.x - b1.x) < ir2.width  * Math.abs(bitmap2.scaleX) + ir1.width  * Math.abs(bitmap1.scaleX)
    && Math.abs(b2.y - b1.y) < ir2.height * Math.abs(bitmap2.scaleY) + ir1.height * Math.abs(bitmap2.scaleY))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants