diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index 814bc8924b..bdb1d7eb3a 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -818,6 +818,24 @@ void PhysicsWorld::rectQuery(PhysicsRectQueryCallbackFunc func, const Rect& rect } } +void PhysicsWorld::pointQuery(PhysicsPointQueryCallbackFunc func, const Point& point, void* data) +{ + CCASSERT(func != nullptr, "callback.report shouldn't be nullptr"); + + if (func != nullptr) + { + RectQueryCallbackInfo info = {this, func, data}; + + PhysicsWorldCallback::continues = true; + cpSpaceBBQuery(this->_info->getSpace(), + PhysicsHelper::rect2cpbb(Rect(point.x - 0.01f, point.y - 0.01f, 0.02f, 0.02f)), + CP_ALL_LAYERS, + CP_NO_GROUP, + (cpSpaceBBQueryFunc)PhysicsWorldCallback::rectQueryCallbackFunc, + &info); + } +} + Array* PhysicsWorld::getShapes(const Point& point) const { Array* arr = Array::create(); diff --git a/cocos/physics/CCPhysicsWorld.h b/cocos/physics/CCPhysicsWorld.h index fc3692d9df..571a0104dc 100644 --- a/cocos/physics/CCPhysicsWorld.h +++ b/cocos/physics/CCPhysicsWorld.h @@ -80,6 +80,7 @@ typedef struct PhysicsRayCastInfo */ typedef std::function PhysicsRayCastCallbackFunc; typedef std::function PhysicsRectQueryCallbackFunc; +typedef PhysicsRectQueryCallbackFunc PhysicsPointQueryCallbackFunc; /** * @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object. @@ -100,6 +101,7 @@ public: void rayCast(PhysicsRayCastCallbackFunc func, const Point& point1, const Point& point2, void* data); void rectQuery(PhysicsRectQueryCallbackFunc func, const Rect& rect, void* data); + void pointQuery(PhysicsPointQueryCallbackFunc func, const Point& point, void* data); Array* getShapes(const Point& point) const; PhysicsShape* getShape(const Point& point) const; Array* getAllBodies() const;