sweetlemons Posted November 25, 2013 Share Posted November 25, 2013 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 Quote Link to comment Share on other sites More sharing options...
robmyers Posted November 25, 2013 Share Posted November 25, 2013 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. Ali BARIN 1 Quote Link to comment Share on other sites More sharing options...
xerver Posted November 25, 2013 Share Posted November 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
sweetlemons Posted November 26, 2013 Author Share Posted November 26, 2013 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. Quote Link to comment Share on other sites More sharing options...
sweetlemons Posted November 26, 2013 Author Share Posted November 26, 2013 Robmyers that worked like a charm. You da man! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.