Jump to content

hitTest in pixi


sweetlemons
 Share

Recommended Posts

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.

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...