diff options
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/canvas_item.h | 2 | ||||
-rw-r--r-- | scene/2d/collision_object_2d.cpp | 4 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 41 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 1 | ||||
-rw-r--r-- | scene/2d/remote_transform_2d.cpp | 7 | ||||
-rw-r--r-- | scene/2d/sprite.cpp | 38 | ||||
-rw-r--r-- | scene/2d/sprite.h | 2 |
7 files changed, 45 insertions, 50 deletions
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 85f8564ac2..1e6a251c9c 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -139,8 +139,6 @@ class CanvasItem : public Node { GDCLASS(CanvasItem, Node); - friend class CanvasLayer; - public: enum BlendMode { diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 52d04ac10a..1e2184bd41 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -38,7 +38,7 @@ void CollisionObject2D::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - Transform2D global_transform = get_global_transform_with_canvas(); + Transform2D global_transform = get_global_transform(); if (area) Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); @@ -64,7 +64,7 @@ void CollisionObject2D::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - Transform2D global_transform = get_global_transform_with_canvas(); + Transform2D global_transform = get_global_transform(); if (only_update_transform_changes && global_transform == last_transform) { return; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 66686f10a8..02213e07d0 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -35,6 +35,19 @@ #include "engine.h" #include "math_funcs.h" #include "scene/scene_string_names.h" +void PhysicsBody2D::_notification(int p_what) { + + /* + switch(p_what) { + + case NOTIFICATION_TRANSFORM_CHANGED: { + + Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_TRANSFORM,get_global_transform()); + + } break; + } + */ +} void PhysicsBody2D::_set_layers(uint32_t p_mask) { @@ -423,7 +436,7 @@ bool RigidBody2D::_test_motion(const Vector2 &p_motion, bool p_infinite_inertia, Physics2DServer::MotionResult *r = NULL; if (p_result.is_valid()) r = p_result->get_result_ptr(); - return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform_with_canvas(), p_motion, p_infinite_inertia, p_margin, r); + return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_infinite_inertia, p_margin, r); } void RigidBody2D::_direct_state_changed(Object *p_state) { @@ -436,7 +449,7 @@ void RigidBody2D::_direct_state_changed(Object *p_state) { set_block_transform_notify(true); // don't want notify (would feedback loop) if (mode != MODE_KINEMATIC) - set_global_transform(get_canvas_transform().affine_inverse() * state->get_transform()); + set_global_transform(state->get_transform()); linear_velocity = state->get_linear_velocity(); angular_velocity = state->get_angular_velocity(); if (sleeping != state->is_sleeping()) { @@ -1131,7 +1144,7 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision Physics2DServer::SeparationResult sep_res[8]; //max 8 rays - Transform2D gt = get_global_transform_with_canvas(); + Transform2D gt = get_global_transform(); Vector2 recover; int hits = Physics2DServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); @@ -1145,7 +1158,7 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision } gt.elements[2] += recover; - set_global_transform(get_canvas_transform().affine_inverse() * gt); + set_global_transform(gt); if (deepest != -1) { r_collision.collider = sep_res[deepest].collider_id; @@ -1166,7 +1179,7 @@ bool KinematicBody2D::separate_raycast_shapes(bool p_infinite_inertia, Collision bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { - Transform2D gt = get_global_transform_with_canvas(); + Transform2D gt = get_global_transform(); Physics2DServer::MotionResult result; bool colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, margin, &result, p_exclude_raycast_shapes); @@ -1185,7 +1198,7 @@ bool KinematicBody2D::move_and_collide(const Vector2 &p_motion, bool p_infinite_ if (!p_test_only) { gt.elements[2] += result.motion; - set_global_transform(get_canvas_transform().affine_inverse() * gt); + set_global_transform(gt); } return colliding; @@ -1259,9 +1272,9 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const if (p_stop_on_slope) { if (Vector2() == lv_n + p_floor_direction) { - Transform2D gt = get_global_transform_with_canvas(); + Transform2D gt = get_global_transform(); gt.elements[2] -= collision.travel; - set_global_transform(get_canvas_transform().affine_inverse() * gt); + set_global_transform(gt); return Vector2(); } } @@ -1310,7 +1323,7 @@ Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_veloci } Collision col; - Transform2D gt = get_global_transform_with_canvas(); + Transform2D gt = get_global_transform(); if (move_and_collide(p_snap, p_infinite_inertia, col, false, true)) { gt.elements[2] += col.travel; @@ -1319,7 +1332,7 @@ Vector2 KinematicBody2D::move_and_slide_with_snap(const Vector2 &p_linear_veloci on_floor_body = col.collider_rid; floor_velocity = col.collider_vel; } - set_global_transform(get_canvas_transform().affine_inverse() * gt); + set_global_transform(gt); } return ret; @@ -1416,22 +1429,22 @@ void KinematicBody2D::_direct_state_changed(Object *p_state) { last_valid_transform = state->get_transform(); set_notify_local_transform(false); - set_global_transform(get_canvas_transform().affine_inverse() * last_valid_transform); + set_global_transform(last_valid_transform); set_notify_local_transform(true); } void KinematicBody2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - last_valid_transform = get_global_transform_with_canvas(); + last_valid_transform = get_global_transform(); } if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { //used by sync to physics, send the new transform to the physics - Transform2D new_transform = get_global_transform_with_canvas(); + Transform2D new_transform = get_global_transform(); Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_TRANSFORM, new_transform); //but then revert changes set_notify_local_transform(false); - set_global_transform(get_canvas_transform().affine_inverse() * last_valid_transform); + set_global_transform(last_valid_transform); set_notify_local_transform(true); } } diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 0900438e3c..852963a721 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -49,6 +49,7 @@ class PhysicsBody2D : public CollisionObject2D { uint32_t _get_layers() const; protected: + void _notification(int p_what); PhysicsBody2D(Physics2DServer::BodyMode p_mode); static void _bind_methods(); diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index 63c3d78dfd..f0274e5206 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -67,7 +67,7 @@ void RemoteTransform2D::_update_remote() { } else { Transform2D n_trans = n->get_global_transform(); Transform2D our_trans = get_global_transform(); - Vector2 n_scale = n->get_global_scale(); + Vector2 n_scale = n->get_scale(); if (!update_remote_position) our_trans.set_origin(n_trans.get_origin()); @@ -131,8 +131,10 @@ void RemoteTransform2D::_notification(int p_what) { void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) { remote_node = p_remote_node; - if (is_inside_tree()) + if (is_inside_tree()) { _update_cache(); + _update_remote(); + } update_configuration_warning(); } @@ -144,6 +146,7 @@ NodePath RemoteTransform2D::get_remote_node() const { void RemoteTransform2D::set_use_global_coordinates(const bool p_enable) { use_global_coordinates = p_enable; + _update_remote(); } bool RemoteTransform2D::get_use_global_coordinates() const { diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index ebe0e81f6e..bb5990fa79 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -298,6 +298,11 @@ int Sprite::get_hframes() const { bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + return is_pixel_opaque(p_point); +} + +bool Sprite::is_pixel_opaque(const Point2 &p_point) const { + if (texture.is_null()) return false; @@ -316,32 +321,6 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc q.y = 1.0f - q.y; q = q * src_rect.size + src_rect.position; - Ref<Image> image; - Ref<AtlasTexture> atlasTexture = texture; - if (atlasTexture.is_null()) { - image = texture->get_data(); - } else { - ERR_FAIL_COND_V(atlasTexture->get_atlas().is_null(), false); - - image = atlasTexture->get_atlas()->get_data(); - - Rect2 region = atlasTexture->get_region(); - Rect2 margin = atlasTexture->get_margin(); - - q -= margin.position; - - if ((q.x > region.size.width) || (q.y > region.size.height)) { - return false; - } - - q += region.position; - } - - ERR_FAIL_COND_V(image.is_null(), false); - if (image->is_compressed()) { - return dst_rect.has_point(p_point); - } - bool is_repeat = texture->get_flags() & Texture::FLAG_REPEAT; bool is_mirrored_repeat = texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT; if (is_repeat) { @@ -363,11 +342,8 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc q.x = MIN(q.x, texture->get_size().width - 1); q.y = MIN(q.y, texture->get_size().height - 1); } - image->lock(); - const Color c = image->get_pixel((int)q.x, (int)q.y); - image->unlock(); - return c.a > 0.01; + return texture->is_pixel_opaque((int)q.x, (int)q.y); } Rect2 Sprite::get_rect() const { @@ -437,6 +413,8 @@ void Sprite::_bind_methods() { ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite::set_region); ClassDB::bind_method(D_METHOD("is_region"), &Sprite::is_region); + ClassDB::bind_method(D_METHOD("is_pixel_opaque", "pos"), &Sprite::is_pixel_opaque); + ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite::set_region_rect); ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite::get_region_rect); diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h index 0a5ff002cd..ab444f89fc 100644 --- a/scene/2d/sprite.h +++ b/scene/2d/sprite.h @@ -75,6 +75,8 @@ public: virtual bool _edit_use_pivot() const; virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; + bool is_pixel_opaque(const Point2 &p_point) const; + virtual Rect2 _edit_get_rect() const; virtual bool _edit_use_rect() const; |