summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-03-17 09:25:35 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-03-17 09:25:35 -0300
commit4cac1e0cb6406609b915797ca41ad125f9b3da08 (patch)
tree662854c17b095df69be917c7c111414f4bfce271 /scene
parenta969e2e6f17d6810771e9c9c31551d57e5d1efdb (diff)
add functions to test overlap with another body or area
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/area_2d.cpp26
-rw-r--r--scene/2d/area_2d.h2
2 files changed, 28 insertions, 0 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index b972ddfa3c..03702d8a13 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -490,6 +490,29 @@ Array Area2D::get_overlapping_areas() const {
return ret;
}
+bool Area2D::overlaps_area(Node* p_area) const {
+
+ ERR_FAIL_NULL_V(p_area,false);
+ const Map<ObjectID,AreaState>::Element *E=area_map.find(p_area->get_instance_ID());
+ if (!E)
+ return false;
+ return E->get().in_tree;
+
+
+
+}
+
+bool Area2D::overlaps_body(Node* p_body) const{
+
+ ERR_FAIL_NULL_V(p_body,false);
+ const Map<ObjectID,BodyState>::Element *E=body_map.find(p_body->get_instance_ID());
+ if (!E)
+ return false;
+ return E->get().in_tree;
+
+}
+
+
void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area2D::_body_enter_tree);
@@ -528,6 +551,9 @@ void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies);
ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area2D::get_overlapping_areas);
+ ObjectTypeDB::bind_method(_MD("overlaps_body:PhysicsBody2D","body"),&Area2D::overlaps_body);
+ ObjectTypeDB::bind_method(_MD("overlaps_area:Area2D","area"),&Area2D::overlaps_area);
+
ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout);
ObjectTypeDB::bind_method(_MD("_area_inout"),&Area2D::_area_inout);
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index bd00f56ae1..6a6c757e0c 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -154,6 +154,8 @@ public:
Array get_overlapping_bodies() const; //function for script
Array get_overlapping_areas() const; //function for script
+ bool overlaps_area(Node* p_area) const;
+ bool overlaps_body(Node* p_body) const;
Area2D();
~Area2D();