sweetlemons

hitTest in pixi

Recommended Posts

Hi Guys

 

Frogive me if this is a silly question but how do I do a hit test using pixi?

 

if(hitTest(obj1, obj2)){ do something};

 

I'm busy writing a function to do this but I would imagine there has to be an easier way.

 

Thanks for your help

 

Lemons

Share this post


Link to post
Share on other sites

If you want to test whether the bounding rectangles of two PIXI.Sprite's overlap you can use:

hitTest(s1.position.x, s1.position.y, s1.width, s1.height,        s2.position.x, s2.position.y, s2.width, s2.height);

where s1 and s2 are the two sprites, and:

hitTest = function(x1, y1, w1, h1,                   x2, y2, w2, h2){    if (x1 + w1 > x2)        if (x1 < x2 + w2)            if (y1 + h1 > y2)                if (y1 < y2 + h2)                    return true;    return false;};

If you need a more complicated hitTest e.g. whether two convex polygons overlap, then I use Box2D for that.

Share this post


Link to post
Share on other sites

Hi Guys

 

Frogive me if this is a silly question but how do I do a hit test using pixi?

 

if(hitTest(obj1, obj2)){ do something};

 

I'm busy writing a function to do this but I would imagine there has to be an easier way.

 

Thanks for your help

 

Lemons

 

Pixi has no methods for this, since it doesn't do any hit testing between objects.

Share this post


Link to post
Share on other sites

Hey guys thanks for the replies, I never got notified that I had any so apologise for delayed response.

 

robmyers, thanks I will give that a shot and let you know.

 

xerver, thats a pity however if the solution by robmyers works I wil let you know.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.