summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/animated_sprite.cpp12
-rw-r--r--scene/2d/animated_sprite.h8
-rw-r--r--scene/2d/back_buffer_copy.cpp2
-rw-r--r--scene/2d/back_buffer_copy.h4
-rw-r--r--scene/2d/canvas_item.cpp54
-rw-r--r--scene/2d/canvas_item.h37
-rw-r--r--scene/2d/collision_polygon_2d.cpp2
-rw-r--r--scene/2d/collision_polygon_2d.h2
-rw-r--r--scene/2d/collision_shape_2d.cpp2
-rw-r--r--scene/2d/collision_shape_2d.h3
-rw-r--r--scene/2d/joints_2d.cpp107
-rw-r--r--scene/2d/joints_2d.h13
-rw-r--r--scene/2d/light_2d.cpp8
-rw-r--r--scene/2d/light_2d.h9
-rw-r--r--scene/2d/node_2d.cpp118
-rw-r--r--scene/2d/node_2d.h30
-rw-r--r--scene/2d/particles_2d.cpp6
-rw-r--r--scene/2d/path_2d.cpp46
-rw-r--r--scene/2d/path_2d.h5
-rw-r--r--scene/2d/physics_body_2d.cpp8
-rw-r--r--scene/2d/polygon_2d.cpp18
-rw-r--r--scene/2d/polygon_2d.h14
-rw-r--r--scene/2d/position_2d.cpp2
-rw-r--r--scene/2d/position_2d.h2
-rw-r--r--scene/2d/screen_button.cpp8
-rw-r--r--scene/2d/screen_button.h2
-rw-r--r--scene/2d/sprite.cpp231
-rw-r--r--scene/2d/sprite.h53
-rw-r--r--scene/2d/tile_map.cpp33
-rw-r--r--scene/2d/tile_map.h6
-rw-r--r--scene/2d/visibility_notifier_2d.cpp2
-rw-r--r--scene/2d/visibility_notifier_2d.h4
32 files changed, 287 insertions, 564 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index 5982556c18..4865858b7d 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -247,16 +247,16 @@ SpriteFrames::SpriteFrames() {
add_animation(SceneStringNames::get_singleton()->_default);
}
-void AnimatedSprite::edit_set_pivot(const Point2 &p_pivot) {
+void AnimatedSprite::_edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
}
-Point2 AnimatedSprite::edit_get_pivot() const {
+Point2 AnimatedSprite::_edit_get_pivot() const {
return get_offset();
}
-bool AnimatedSprite::edit_has_pivot() const {
+bool AnimatedSprite::_edit_use_pivot() const {
return true;
}
@@ -509,17 +509,17 @@ bool AnimatedSprite::is_flipped_v() const {
return vflip;
}
-Rect2 AnimatedSprite::get_item_rect() const {
+Rect2 AnimatedSprite::_edit_get_rect() const {
if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
- return Node2D::get_item_rect();
+ return Node2D::_edit_get_rect();
}
Ref<Texture> t;
if (animation)
t = frames->get_frame(animation, frame);
if (t.is_null())
- return Node2D::get_item_rect();
+ return Node2D::_edit_get_rect();
Size2i s = t->get_size();
Point2 ofs = offset;
diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h
index 6c660d0381..a8d0db021a 100644
--- a/scene/2d/animated_sprite.h
+++ b/scene/2d/animated_sprite.h
@@ -149,9 +149,9 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
- virtual void edit_set_pivot(const Point2 &p_pivot);
- virtual Point2 edit_get_pivot() const;
- virtual bool edit_has_pivot() const;
+ virtual void _edit_set_pivot(const Point2 &p_pivot);
+ virtual Point2 _edit_get_pivot() const;
+ virtual bool _edit_use_pivot() const;
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
Ref<SpriteFrames> get_sprite_frames() const;
@@ -181,7 +181,7 @@ public:
void set_modulate(const Color &p_color);
Color get_modulate() const;
- virtual Rect2 get_item_rect() const;
+ virtual Rect2 _edit_get_rect() const;
virtual String get_configuration_warning() const;
AnimatedSprite();
diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp
index 2858ddaad5..e4f52a227a 100644
--- a/scene/2d/back_buffer_copy.cpp
+++ b/scene/2d/back_buffer_copy.cpp
@@ -49,7 +49,7 @@ void BackBufferCopy::_update_copy_mode() {
}
}
-Rect2 BackBufferCopy::get_item_rect() const {
+Rect2 BackBufferCopy::_edit_get_rect() const {
return rect;
}
diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h
index 2424dd7b19..cfd632d755 100644
--- a/scene/2d/back_buffer_copy.h
+++ b/scene/2d/back_buffer_copy.h
@@ -52,14 +52,14 @@ protected:
static void _bind_methods();
public:
+ Rect2 _edit_get_rect() const;
+
void set_rect(const Rect2 &p_rect);
Rect2 get_rect() const;
void set_copy_mode(CopyMode p_mode);
CopyMode get_copy_mode() const;
- Rect2 get_item_rect() const;
-
BackBufferCopy();
~BackBufferCopy();
};
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index b41ba7f590..66abe1baa8 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -178,6 +178,12 @@ CanvasItemMaterial::LightMode CanvasItemMaterial::get_light_mode() const {
void CanvasItemMaterial::_validate_property(PropertyInfo &property) const {
}
+RID CanvasItemMaterial::get_shader_rid() const {
+
+ ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
+ return shader_map[current_key].shader;
+}
+
void CanvasItemMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
@@ -300,22 +306,7 @@ void CanvasItem::hide() {
_change_notify("visible");
}
-Variant CanvasItem::edit_get_state() const {
-
- return Variant();
-}
-void CanvasItem::edit_set_state(const Variant &p_state) {
-}
-
-void CanvasItem::edit_set_rect(const Rect2 &p_edit_rect) {
-
- //used by editors, implement at will
-}
-
-void CanvasItem::edit_rotate(float p_rot) {
-}
-
-Size2 CanvasItem::edit_get_minimum_size() const {
+Size2 CanvasItem::_edit_get_minimum_size() const {
return Size2(-1, -1); //no limit
}
@@ -935,15 +926,22 @@ void CanvasItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("_toplevel_raise_self"), &CanvasItem::_toplevel_raise_self);
ClassDB::bind_method(D_METHOD("_update_callback"), &CanvasItem::_update_callback);
-
- ClassDB::bind_method(D_METHOD("edit_set_state", "state"), &CanvasItem::edit_set_state);
- ClassDB::bind_method(D_METHOD("edit_get_state"), &CanvasItem::edit_get_state);
- ClassDB::bind_method(D_METHOD("edit_set_rect", "rect"), &CanvasItem::edit_set_rect);
- ClassDB::bind_method(D_METHOD("edit_rotate", "degrees"), &CanvasItem::edit_rotate);
-
- ClassDB::bind_method(D_METHOD("get_item_rect"), &CanvasItem::get_item_rect);
- ClassDB::bind_method(D_METHOD("get_item_and_children_rect"), &CanvasItem::get_item_and_children_rect);
- //ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform);
+ ClassDB::bind_method(D_METHOD("_edit_set_state", "state"), &CanvasItem::_edit_set_state);
+ ClassDB::bind_method(D_METHOD("_edit_get_state"), &CanvasItem::_edit_get_state);
+
+ ClassDB::bind_method(D_METHOD("_edit_set_position", "position"), &CanvasItem::_edit_set_position);
+ ClassDB::bind_method(D_METHOD("_edit_get_position"), &CanvasItem::_edit_get_position);
+ ClassDB::bind_method(D_METHOD("_edit_use_position"), &CanvasItem::_edit_use_position);
+ ClassDB::bind_method(D_METHOD("_edit_set_rect", "rect"), &CanvasItem::_edit_set_rect);
+ ClassDB::bind_method(D_METHOD("_edit_get_rect"), &CanvasItem::_edit_get_rect);
+ ClassDB::bind_method(D_METHOD("_edit_use_rect"), &CanvasItem::_edit_use_rect);
+ ClassDB::bind_method(D_METHOD("_edit_get_item_and_children_rect"), &CanvasItem::_edit_get_item_and_children_rect);
+ ClassDB::bind_method(D_METHOD("_edit_set_rotation", "degrees"), &CanvasItem::_edit_set_rotation);
+ ClassDB::bind_method(D_METHOD("_edit_get_rotation"), &CanvasItem::_edit_get_rotation);
+ ClassDB::bind_method(D_METHOD("_edit_use_rotation"), &CanvasItem::_edit_use_rotation);
+ ClassDB::bind_method(D_METHOD("_edit_set_pivot", "pivot"), &CanvasItem::_edit_set_pivot);
+ ClassDB::bind_method(D_METHOD("_edit_get_pivot"), &CanvasItem::_edit_get_pivot);
+ ClassDB::bind_method(D_METHOD("_edit_use_pivot"), &CanvasItem::_edit_use_pivot);
ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
@@ -1113,14 +1111,14 @@ int CanvasItem::get_canvas_layer() const {
return 0;
}
-Rect2 CanvasItem::get_item_and_children_rect() const {
+Rect2 CanvasItem::_edit_get_item_and_children_rect() const {
- Rect2 rect = get_item_rect();
+ Rect2 rect = _edit_get_rect();
for (int i = 0; i < get_child_count(); i++) {
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));
if (c) {
- Rect2 sir = c->get_transform().xform(c->get_item_and_children_rect());
+ Rect2 sir = c->get_transform().xform(c->_edit_get_item_and_children_rect());
rect = rect.merge(sir);
}
}
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 1afbd150a2..c877a94755 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -121,6 +121,8 @@ public:
static void finish_shaders();
static void flush_changes();
+ RID get_shader_rid() const;
+
CanvasItemMaterial();
virtual ~CanvasItemMaterial();
};
@@ -214,11 +216,31 @@ public:
/* EDITOR */
- virtual Variant edit_get_state() const;
- virtual void edit_set_state(const Variant &p_state);
- virtual void edit_set_rect(const Rect2 &p_edit_rect);
- virtual void edit_rotate(float p_rot);
- virtual Size2 edit_get_minimum_size() const;
+ virtual void _edit_set_state(const Dictionary &p_state){};
+ virtual Dictionary _edit_get_state() const { return Dictionary(); };
+
+ // Used to move/select the node
+ virtual void _edit_set_position(const Point2 &p_position){};
+ virtual Point2 _edit_get_position() const { return Point2(); };
+ virtual bool _edit_use_position() const { return false; };
+
+ // Used to resize/move/select the node
+ virtual void _edit_set_rect(const Rect2 &p_rect){};
+ virtual Rect2 _edit_get_rect() const { return Rect2(-32, -32, 64, 64); };
+ Rect2 _edit_get_item_and_children_rect() const;
+ virtual bool _edit_use_rect() const { return false; };
+
+ // Used to rotate the node
+ virtual void _edit_set_rotation(float p_rotation){};
+ virtual float _edit_get_rotation() const { return 0.0; };
+ virtual bool _edit_use_rotation() const { return false; };
+
+ // Used to set a pivot
+ virtual void _edit_set_pivot(const Point2 &p_pivot){};
+ virtual Point2 _edit_get_pivot() const { return Point2(); };
+ virtual bool _edit_use_pivot() const { return false; };
+
+ virtual Size2 _edit_get_minimum_size() const;
/* VISIBILITY */
@@ -248,7 +270,7 @@ public:
void draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color);
void draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1), const Ref<Texture> &p_normal_map = Ref<Texture>());
void draw_texture_rect(const Ref<Texture> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>());
- void draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true);
+ void draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = false);
void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect);
void draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture = Ref<Texture>(), float p_width = 1, const Ref<Texture> &p_normal_map = Ref<Texture>());
void draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture> p_texture = Ref<Texture>(), const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_antialiased = false);
@@ -270,14 +292,11 @@ public:
CanvasItem *get_parent_item() const;
- virtual Rect2 get_item_rect() const = 0;
virtual Transform2D get_transform() const = 0;
virtual Transform2D get_global_transform() const;
virtual Transform2D get_global_transform_with_canvas() const;
- Rect2 get_item_and_children_rect() const;
-
CanvasItem *get_toplevel() const;
_FORCE_INLINE_ RID get_canvas_item() const { return canvas_item; }
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index a840744c78..92855299ae 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -243,7 +243,7 @@ CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const {
return build_mode;
}
-Rect2 CollisionPolygon2D::get_item_rect() const {
+Rect2 CollisionPolygon2D::_edit_get_rect() const {
return aabb;
}
diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h
index c9ec860e36..2fb08a4599 100644
--- a/scene/2d/collision_polygon_2d.h
+++ b/scene/2d/collision_polygon_2d.h
@@ -69,7 +69,7 @@ public:
void set_polygon(const Vector<Point2> &p_polygon);
Vector<Point2> get_polygon() const;
- virtual Rect2 get_item_rect() const;
+ virtual Rect2 _edit_get_rect() const;
virtual String get_configuration_warning() const;
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index 0758f4a9bf..f7cb5473e3 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -158,7 +158,7 @@ Ref<Shape2D> CollisionShape2D::get_shape() const {
return shape;
}
-Rect2 CollisionShape2D::get_item_rect() const {
+Rect2 CollisionShape2D::_edit_get_rect() const {
return rect;
}
diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h
index 04203a75b4..4745c659c8 100644
--- a/scene/2d/collision_shape_2d.h
+++ b/scene/2d/collision_shape_2d.h
@@ -51,9 +51,10 @@ protected:
static void _bind_methods();
public:
+ virtual Rect2 _edit_get_rect() const;
+
void set_shape(const Ref<Shape2D> &p_shape);
Ref<Shape2D> get_shape() const;
- virtual Rect2 get_item_rect() const;
void set_disabled(bool p_disabled);
bool is_disabled() const;
diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp
index 69bad1623f..b98cdcc365 100644
--- a/scene/2d/joints_2d.cpp
+++ b/scene/2d/joints_2d.cpp
@@ -33,19 +33,49 @@
#include "physics_body_2d.h"
#include "servers/physics_2d_server.h"
-void Joint2D::_update_joint() {
-
- if (!is_inside_tree())
- return;
+void Joint2D::_update_joint(bool p_only_free) {
if (joint.is_valid()) {
+ if (ba.is_valid() && bb.is_valid())
+ Physics2DServer::get_singleton()->body_remove_collision_exception(ba, bb);
+
Physics2DServer::get_singleton()->free(joint);
+ joint = RID();
+ ba = RID();
+ bb = RID();
}
- joint = RID();
+ if (p_only_free || !is_inside_tree())
+ return;
+
+ Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
+ Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
+
+ if (!node_a || !node_b)
+ return;
+
+ PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a);
+ PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b);
+
+ if (!body_a || !body_b)
+ return;
+
+ if (!body_a) {
+ SWAP(body_a, body_b);
+ }
+
+ joint = _configure_joint(body_a, body_b);
+
+ if (!joint.is_valid())
+ return;
- joint = _configure_joint();
Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias);
+
+ ba = body_a->get_rid();
+ bb = body_b->get_rid();
+
+ if (exclude_from_collision)
+ Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
}
void Joint2D::set_node_a(const NodePath &p_node_a) {
@@ -83,9 +113,7 @@ void Joint2D::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
if (joint.is_valid()) {
-
- Physics2DServer::get_singleton()->free(joint);
- joint = RID();
+ _update_joint(true);
}
} break;
}
@@ -164,29 +192,8 @@ void PinJoint2D::_notification(int p_what) {
}
}
-RID PinJoint2D::_configure_joint() {
-
- Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
- Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
-
- if (!node_a && !node_b)
- return RID();
+RID PinJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) {
- PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a);
- PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b);
-
- if (!body_a && !body_b)
- return RID();
-
- if (!body_a) {
- SWAP(body_a, body_b);
- } else if (body_b) {
- //add a collision exception between both
- if (get_exclude_nodes_from_collision())
- Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
- else
- Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid());
- }
RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(), body_a->get_rid(), body_b ? body_b->get_rid() : RID());
Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness);
return pj;
@@ -241,24 +248,7 @@ void GrooveJoint2D::_notification(int p_what) {
}
}
-RID GrooveJoint2D::_configure_joint() {
-
- Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
- Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
-
- if (!node_a || !node_b)
- return RID();
-
- PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a);
- PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b);
-
- if (!body_a || !body_b)
- return RID();
-
- if (get_exclude_nodes_from_collision())
- Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
- else
- Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid());
+RID GrooveJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) {
Transform2D gt = get_global_transform();
Vector2 groove_A1 = gt.get_origin();
@@ -330,24 +320,7 @@ void DampedSpringJoint2D::_notification(int p_what) {
}
}
-RID DampedSpringJoint2D::_configure_joint() {
-
- Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
- Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
-
- if (!node_a || !node_b)
- return RID();
-
- PhysicsBody2D *body_a = Object::cast_to<PhysicsBody2D>(node_a);
- PhysicsBody2D *body_b = Object::cast_to<PhysicsBody2D>(node_b);
-
- if (!body_a || !body_b)
- return RID();
-
- if (get_exclude_nodes_from_collision())
- Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
- else
- Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid());
+RID DampedSpringJoint2D::_configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) {
Transform2D gt = get_global_transform();
Vector2 anchor_A = gt.get_origin();
diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h
index 685299abc6..a6292be51c 100644
--- a/scene/2d/joints_2d.h
+++ b/scene/2d/joints_2d.h
@@ -32,11 +32,14 @@
#include "node_2d.h"
+class PhysicsBody2D;
+
class Joint2D : public Node2D {
GDCLASS(Joint2D, Node2D);
RID joint;
+ RID ba, bb;
NodePath a;
NodePath b;
@@ -45,10 +48,10 @@ class Joint2D : public Node2D {
bool exclude_from_collision;
protected:
- void _update_joint();
+ void _update_joint(bool p_only_free = false);
void _notification(int p_what);
- virtual RID _configure_joint() = 0;
+ virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b) = 0;
static void _bind_methods();
@@ -77,7 +80,7 @@ class PinJoint2D : public Joint2D {
protected:
void _notification(int p_what);
- virtual RID _configure_joint();
+ virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
static void _bind_methods();
public:
@@ -96,7 +99,7 @@ class GrooveJoint2D : public Joint2D {
protected:
void _notification(int p_what);
- virtual RID _configure_joint();
+ virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
static void _bind_methods();
public:
@@ -120,7 +123,7 @@ class DampedSpringJoint2D : public Joint2D {
protected:
void _notification(int p_what);
- virtual RID _configure_joint();
+ virtual RID _configure_joint(PhysicsBody2D *body_a, PhysicsBody2D *body_b);
static void _bind_methods();
public:
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index 516acefe2a..d2b987e037 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -32,21 +32,21 @@
#include "engine.h"
#include "servers/visual_server.h"
-void Light2D::edit_set_pivot(const Point2 &p_pivot) {
+void Light2D::_edit_set_pivot(const Point2 &p_pivot) {
set_texture_offset(p_pivot);
}
-Point2 Light2D::edit_get_pivot() const {
+Point2 Light2D::_edit_get_pivot() const {
return get_texture_offset();
}
-bool Light2D::edit_has_pivot() const {
+bool Light2D::_edit_use_pivot() const {
return true;
}
-Rect2 Light2D::get_item_rect() const {
+Rect2 Light2D::_edit_get_rect() const {
if (texture.is_null())
return Rect2(0, 0, 1, 1);
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index f6bc943adb..9b9da8379f 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -84,9 +84,10 @@ protected:
static void _bind_methods();
public:
- virtual void edit_set_pivot(const Point2 &p_pivot);
- virtual Point2 edit_get_pivot() const;
- virtual bool edit_has_pivot() const;
+ virtual void _edit_set_pivot(const Point2 &p_pivot);
+ virtual Point2 _edit_get_pivot() const;
+ virtual bool _edit_use_pivot() const;
+ virtual Rect2 _edit_get_rect() const;
void set_enabled(bool p_enabled);
bool is_enabled() const;
@@ -151,8 +152,6 @@ public:
void set_shadow_smooth(float p_amount);
float get_shadow_smooth() const;
- virtual Rect2 get_item_rect() const;
-
String get_configuration_warning() const;
Light2D();
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index e62b59dd4d..45f780e50e 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -34,45 +34,39 @@
#include "scene/main/viewport.h"
#include "servers/visual_server.h"
-void Node2D::edit_set_pivot(const Point2 &p_pivot) {
-}
-
-Point2 Node2D::edit_get_pivot() const {
-
- return Point2();
-}
-bool Node2D::edit_has_pivot() const {
+Dictionary Node2D::_edit_get_state() const {
- return false;
-}
-
-Variant Node2D::edit_get_state() const {
-
- Array state;
- state.push_back(get_position());
- state.push_back(get_rotation());
- state.push_back(get_scale());
+ Dictionary state;
+ state["position"] = get_position();
+ state["rotation"] = get_rotation();
+ state["scale"] = get_scale();
return state;
}
-void Node2D::edit_set_state(const Variant &p_state) {
+void Node2D::_edit_set_state(const Dictionary &p_state) {
- Array state = p_state;
- ERR_FAIL_COND(state.size() != 3);
+ Dictionary state = p_state;
+ pos = state["position"];
+ angle = state["rotation"];
+ _scale = state["scale"];
- pos = state[0];
- angle = state[1];
- _scale = state[2];
_update_transform();
_change_notify("rotation");
- _change_notify("rotation_deg");
+ _change_notify("rotation_degrees");
_change_notify("scale");
_change_notify("position");
}
-void Node2D::edit_set_rect(const Rect2 &p_edit_rect) {
+void Node2D::_edit_set_position(const Point2 &p_position) {
+ pos = p_position;
+}
- Rect2 r = get_item_rect();
+Point2 Node2D::_edit_get_position() const {
+ return pos;
+}
+
+void Node2D::_edit_set_rect(const Rect2 &p_edit_rect) {
+ Rect2 r = _edit_get_rect();
Vector2 zero_offset;
if (r.size.x != 0)
@@ -101,12 +95,23 @@ void Node2D::edit_set_rect(const Rect2 &p_edit_rect) {
_change_notify("position");
}
-void Node2D::edit_rotate(float p_rot) {
+bool Node2D::_edit_use_rect() const {
+ return true;
+}
- angle += p_rot;
+void Node2D::_edit_set_rotation(float p_rotation) {
+ angle = p_rotation;
_update_transform();
_change_notify("rotation");
- _change_notify("rotation_deg");
+ _change_notify("rotation_degrees");
+}
+
+float Node2D::_edit_get_rotation() const {
+ return angle;
+}
+
+bool Node2D::_edit_use_rotation() const {
+ return true;
}
void Node2D::_update_xform_values() {
@@ -147,22 +152,14 @@ void Node2D::set_rotation(float p_radians) {
angle = p_radians;
_update_transform();
_change_notify("rotation");
- _change_notify("rotation_deg");
+ _change_notify("rotation_degrees");
}
-void Node2D::set_rotation_in_degrees(float p_degrees) {
+void Node2D::set_rotation_degrees(float p_degrees) {
set_rotation(Math::deg2rad(p_degrees));
}
-// Kept for compatibility after rename to set_rotd.
-// Could be removed after a couple releases.
-void Node2D::_set_rotd(float p_degrees) {
-
- WARN_PRINT("Deprecated method Node2D._set_rotd(): This method was renamed to set_rotd. Please adapt your code accordingly, as the old method will be obsoleted.");
- set_rotation_in_degrees(p_degrees);
-}
-
void Node2D::set_scale(const Size2 &p_scale) {
if (_xform_dirty)
@@ -182,23 +179,19 @@ Point2 Node2D::get_position() const {
((Node2D *)this)->_update_xform_values();
return pos;
}
+
float Node2D::get_rotation() const {
if (_xform_dirty)
((Node2D *)this)->_update_xform_values();
return angle;
}
-float Node2D::get_rotation_in_degrees() const {
+
+float Node2D::get_rotation_degrees() const {
return Math::rad2deg(get_rotation());
}
-// Kept for compatibility after rename to get_rotd.
-// Could be removed after a couple releases.
-float Node2D::_get_rotd() const {
- WARN_PRINT("Deprecated method Node2D._get_rotd(): This method was renamed to get_rotd. Please adapt your code accordingly, as the old method will be obsoleted.");
- return get_rotation_in_degrees();
-}
Size2 Node2D::get_scale() const {
if (_xform_dirty)
((Node2D *)this)->_update_xform_values();
@@ -217,17 +210,6 @@ Transform2D Node2D::get_transform() const {
return _mat;
}
-Rect2 Node2D::get_item_rect() const {
-
- if (get_script_instance()) {
- Variant::CallError err;
- Rect2 r = get_script_instance()->call("_get_item_rect", NULL, 0, err);
- if (err.error == Variant::CallError::CALL_OK)
- return r;
- }
- return Rect2(Point2(-32, -32), Size2(64, 64));
-}
-
void Node2D::rotate(float p_radians) {
set_rotation(get_rotation() + p_radians);
@@ -299,12 +281,12 @@ void Node2D::set_global_rotation(float p_radians) {
}
}
-float Node2D::get_global_rotation_in_degrees() const {
+float Node2D::get_global_rotation_degrees() const {
return Math::rad2deg(get_global_rotation());
}
-void Node2D::set_global_rotation_in_degrees(float p_degrees) {
+void Node2D::set_global_rotation_degrees(float p_degrees) {
set_global_rotation(Math::deg2rad(p_degrees));
}
@@ -410,18 +392,14 @@ Point2 Node2D::to_global(Point2 p_local) const {
void Node2D::_bind_methods() {
- // TODO: Obsolete those two methods (old name) properly (GH-4397)
- ClassDB::bind_method(D_METHOD("_get_rotd"), &Node2D::_get_rotd);
- ClassDB::bind_method(D_METHOD("_set_rotd", "degrees"), &Node2D::_set_rotd);
-
ClassDB::bind_method(D_METHOD("set_position", "position"), &Node2D::set_position);
ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Node2D::set_rotation);
- ClassDB::bind_method(D_METHOD("set_rotation_in_degrees", "degrees"), &Node2D::set_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("set_rotation_degrees", "degrees"), &Node2D::set_rotation_degrees);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node2D::set_scale);
ClassDB::bind_method(D_METHOD("get_position"), &Node2D::get_position);
ClassDB::bind_method(D_METHOD("get_rotation"), &Node2D::get_rotation);
- ClassDB::bind_method(D_METHOD("get_rotation_in_degrees"), &Node2D::get_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node2D::get_rotation_degrees);
ClassDB::bind_method(D_METHOD("get_scale"), &Node2D::get_scale);
ClassDB::bind_method(D_METHOD("rotate", "radians"), &Node2D::rotate);
@@ -435,8 +413,8 @@ void Node2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_global_position"), &Node2D::get_global_position);
ClassDB::bind_method(D_METHOD("set_global_rotation", "radians"), &Node2D::set_global_rotation);
ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node2D::get_global_rotation);
- ClassDB::bind_method(D_METHOD("set_global_rotation_in_degrees", "degrees"), &Node2D::set_global_rotation_in_degrees);
- ClassDB::bind_method(D_METHOD("get_global_rotation_in_degrees"), &Node2D::get_global_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("set_global_rotation_degrees", "degrees"), &Node2D::set_global_rotation_degrees);
+ ClassDB::bind_method(D_METHOD("get_global_rotation_degrees"), &Node2D::get_global_rotation_degrees);
ClassDB::bind_method(D_METHOD("set_global_scale", "scale"), &Node2D::set_global_scale);
ClassDB::bind_method(D_METHOD("get_global_scale"), &Node2D::get_global_scale);
@@ -455,20 +433,18 @@ void Node2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &Node2D::set_z_as_relative);
ClassDB::bind_method(D_METHOD("is_z_relative"), &Node2D::is_z_relative);
- ClassDB::bind_method(D_METHOD("edit_set_pivot", "pivot"), &Node2D::edit_set_pivot);
-
ClassDB::bind_method(D_METHOD("get_relative_transform_to_parent", "parent"), &Node2D::get_relative_transform_to_parent);
ADD_GROUP("Transform", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation");
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rotation_deg", PROPERTY_HINT_RANGE, "-1440,1440,0.1", PROPERTY_USAGE_EDITOR), "set_rotation_in_degrees", "get_rotation_in_degrees");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rotation_degrees", PROPERTY_HINT_RANGE, "-1440,1440,0.1", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform", PROPERTY_HINT_NONE, "", 0), "set_transform", "get_transform");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_position", PROPERTY_HINT_NONE, "", 0), "set_global_position", "get_global_position");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_rotation", PROPERTY_HINT_NONE, "", 0), "set_global_rotation", "get_global_rotation");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_rotation_deg", PROPERTY_HINT_NONE, "", 0), "set_global_rotation_in_degrees", "get_global_rotation_in_degrees");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_rotation_degrees", PROPERTY_HINT_NONE, "", 0), "set_global_rotation_degrees", "get_global_rotation_degrees");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_scale", PROPERTY_HINT_NONE, "", 0), "set_global_scale", "get_global_scale");
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform");
diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h
index 19aafc81ff..e1e07f2895 100644
--- a/scene/2d/node_2d.h
+++ b/scene/2d/node_2d.h
@@ -48,10 +48,6 @@ class Node2D : public CanvasItem {
void _update_transform();
- // Deprecated, should be removed in a future version.
- void _set_rotd(float p_degrees);
- float _get_rotd() const;
-
void _update_xform_values();
protected:
@@ -60,17 +56,20 @@ protected:
static void _bind_methods();
public:
- virtual Variant edit_get_state() const;
- virtual void edit_set_state(const Variant &p_state);
- virtual void edit_set_rect(const Rect2 &p_edit_rect);
- virtual void edit_rotate(float p_rot);
- virtual void edit_set_pivot(const Point2 &p_pivot);
- virtual Point2 edit_get_pivot() const;
- virtual bool edit_has_pivot() const;
+ virtual Dictionary _edit_get_state() const;
+ virtual void _edit_set_state(const Dictionary &p_state);
+
+ virtual void _edit_set_position(const Point2 &p_position);
+ virtual Point2 _edit_get_position() const;
+ virtual void _edit_set_rect(const Rect2 &p_edit_rect);
+ virtual bool _edit_use_rect() const;
+ virtual void _edit_set_rotation(float p_rotation);
+ virtual float _edit_get_rotation() const;
+ virtual bool _edit_use_rotation() const;
void set_position(const Point2 &p_pos);
void set_rotation(float p_radians);
- void set_rotation_in_degrees(float p_degrees);
+ void set_rotation_degrees(float p_degrees);
void set_scale(const Size2 &p_scale);
void rotate(float p_radians);
@@ -82,20 +81,19 @@ public:
Point2 get_position() const;
float get_rotation() const;
- float get_rotation_in_degrees() const;
+ float get_rotation_degrees() const;
Size2 get_scale() const;
Point2 get_global_position() const;
float get_global_rotation() const;
- float get_global_rotation_in_degrees() const;
+ float get_global_rotation_degrees() const;
Size2 get_global_scale() const;
- virtual Rect2 get_item_rect() const;
void set_transform(const Transform2D &p_transform);
void set_global_transform(const Transform2D &p_transform);
void set_global_position(const Point2 &p_pos);
void set_global_rotation(float p_radians);
- void set_global_rotation_in_degrees(float p_degrees);
+ void set_global_rotation_degrees(float p_degrees);
void set_global_scale(const Size2 &p_scale);
void set_z(int p_z);
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index c146ac08c2..aee5d89150 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -77,7 +77,7 @@ void Particles2D::set_randomness_ratio(float p_ratio) {
void Particles2D::set_visibility_rect(const Rect2 &p_aabb) {
visibility_rect = p_aabb;
- Rect3 aabb;
+ AABB aabb;
aabb.position.x = p_aabb.position.x;
aabb.position.y = p_aabb.position.y;
aabb.size.x = p_aabb.size.x;
@@ -223,7 +223,7 @@ String Particles2D::get_configuration_warning() const {
Rect2 Particles2D::capture_rect() const {
- Rect3 aabb = VS::get_singleton()->particles_get_current_aabb(particles);
+ AABB aabb = VS::get_singleton()->particles_get_current_aabb(particles);
Rect2 r;
r.position.x = aabb.position.x;
r.position.y = aabb.position.y;
@@ -378,7 +378,7 @@ void Particles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
ADD_GROUP("Drawing", "");
- ADD_PROPERTY(PropertyInfo(Variant::RECT3, "visibility_rect"), "set_visibility_rect", "get_visibility_rect");
+ ADD_PROPERTY(PropertyInfo(Variant::AABB, "visibility_rect"), "set_visibility_rect", "get_visibility_rect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime"), "set_draw_order", "get_draw_order");
ADD_GROUP("Process Material", "process_");
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index 8413be1ca9..55c055e34f 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -107,28 +107,39 @@ void PathFollow2D::_update_transform() {
if (!c.is_valid())
return;
+ if (delta_offset == 0) {
+ return;
+ }
+
float o = offset;
if (loop)
o = Math::fposmod(o, c->get_baked_length());
Vector2 pos = c->interpolate_baked(o, cubic);
+ Vector2 offset = Vector2(h_offset, v_offset);
+
+ Transform2D t = get_transform();
+ t.set_origin(pos);
+
if (rotate) {
- Vector2 n = (c->interpolate_baked(o + lookahead, cubic) - pos).normalized();
- Vector2 t = -n.tangent();
- pos += n * h_offset;
- pos += t * v_offset;
+ Vector2 t_prev = (pos - c->interpolate_baked(o - delta_offset, cubic)).normalized();
+ Vector2 t_cur = (c->interpolate_baked(o + delta_offset, cubic) - pos).normalized();
+
+ float dot = t_prev.dot(t_cur);
+ float angle = Math::acos(CLAMP(dot, -1, 1));
+
+ t.rotate(angle);
- set_rotation(t.angle());
+ t.translate(offset);
} else {
- pos.x += h_offset;
- pos.y += v_offset;
+ t.set_origin(t.get_origin() + offset);
}
- set_position(pos);
+ set_transform(t);
}
void PathFollow2D::_notification(int p_what) {
@@ -176,8 +187,6 @@ bool PathFollow2D::_set(const StringName &p_name, const Variant &p_value) {
set_cubic_interpolation(p_value);
} else if (String(p_name) == "loop") {
set_loop(p_value);
- } else if (String(p_name) == "lookahead") {
- set_lookahead(p_value);
} else
return false;
@@ -200,8 +209,6 @@ bool PathFollow2D::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = cubic;
} else if (String(p_name) == "loop") {
r_ret = loop;
- } else if (String(p_name) == "lookahead") {
- r_ret = lookahead;
} else
return false;
@@ -219,7 +226,6 @@ void PathFollow2D::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::BOOL, "rotate"));
p_list->push_back(PropertyInfo(Variant::BOOL, "cubic_interp"));
p_list->push_back(PropertyInfo(Variant::BOOL, "loop"));
- p_list->push_back(PropertyInfo(Variant::REAL, "lookahead", PROPERTY_HINT_RANGE, "0.001,1024.0,0.001"));
}
String PathFollow2D::get_configuration_warning() const {
@@ -259,7 +265,7 @@ void PathFollow2D::_bind_methods() {
}
void PathFollow2D::set_offset(float p_offset) {
-
+ delta_offset = p_offset - offset;
offset = p_offset;
if (path)
_update_transform();
@@ -310,16 +316,6 @@ float PathFollow2D::get_unit_offset() const {
return 0;
}
-void PathFollow2D::set_lookahead(float p_lookahead) {
-
- lookahead = p_lookahead;
-}
-
-float PathFollow2D::get_lookahead() const {
-
- return lookahead;
-}
-
void PathFollow2D::set_rotate(bool p_rotate) {
rotate = p_rotate;
@@ -344,11 +340,11 @@ bool PathFollow2D::has_loop() const {
PathFollow2D::PathFollow2D() {
offset = 0;
+ delta_offset = 0;
h_offset = 0;
v_offset = 0;
path = NULL;
rotate = true;
cubic = true;
loop = true;
- lookahead = 4;
}
diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h
index 88a0abdea9..f5ba3a3d32 100644
--- a/scene/2d/path_2d.h
+++ b/scene/2d/path_2d.h
@@ -60,9 +60,9 @@ public:
private:
Path2D *path;
real_t offset;
+ real_t delta_offset; // change in offset since last _update_transform
real_t h_offset;
real_t v_offset;
- real_t lookahead;
bool cubic;
bool loop;
bool rotate;
@@ -90,9 +90,6 @@ public:
void set_unit_offset(float p_unit_offset);
float get_unit_offset() const;
- void set_lookahead(float p_lookahead);
- float get_lookahead() const;
-
void set_loop(bool p_loop);
bool has_loop() const;
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index f0ee64a53f..1f6127e6eb 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -133,8 +133,9 @@ bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const {
}
PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode)
- : CollisionObject2D(Physics2DServer::get_singleton()->body_create(p_mode), false) {
+ : CollisionObject2D(Physics2DServer::get_singleton()->body_create(), false) {
+ Physics2DServer::get_singleton()->body_set_mode(get_rid(), p_mode);
collision_layer = 1;
collision_mask = 1;
set_pickable(false);
@@ -1027,7 +1028,10 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const
on_floor = true;
floor_velocity = collision.collider_vel;
- if (collision.travel.length() < 1 && ABS((lv.x - floor_velocity.x)) < p_slope_stop_min_velocity) {
+ Vector2 rel_v = lv - floor_velocity;
+ Vector2 hv = rel_v - p_floor_direction * p_floor_direction.dot(rel_v);
+
+ if (collision.travel.length() < 1 && hv.length() < p_slope_stop_min_velocity) {
Transform2D gt = get_global_transform();
gt.elements[2] -= collision.travel;
set_global_transform(gt);
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 197c74352e..3f2ad19e51 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include "polygon_2d.h"
-Rect2 Polygon2D::get_item_rect() const {
+Rect2 Polygon2D::_edit_get_rect() const {
if (rect_cache_dirty) {
int l = polygon.size();
@@ -49,16 +49,16 @@ Rect2 Polygon2D::get_item_rect() const {
return item_rect;
}
-void Polygon2D::edit_set_pivot(const Point2 &p_pivot) {
+void Polygon2D::_edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
}
-Point2 Polygon2D::edit_get_pivot() const {
+Point2 Polygon2D::_edit_get_pivot() const {
return get_offset();
}
-bool Polygon2D::edit_has_pivot() const {
+bool Polygon2D::_edit_use_pivot() const {
return true;
}
@@ -264,11 +264,11 @@ float Polygon2D::get_texture_rotation() const {
return tex_rot;
}
-void Polygon2D::_set_texture_rotationd(float p_rot) {
+void Polygon2D::set_texture_rotation_degrees(float p_rot) {
set_texture_rotation(Math::deg2rad(p_rot));
}
-float Polygon2D::_get_texture_rotationd() const {
+float Polygon2D::get_texture_rotation_degrees() const {
return Math::rad2deg(get_texture_rotation());
}
@@ -348,8 +348,8 @@ void Polygon2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture_rotation", "texture_rotation"), &Polygon2D::set_texture_rotation);
ClassDB::bind_method(D_METHOD("get_texture_rotation"), &Polygon2D::get_texture_rotation);
- ClassDB::bind_method(D_METHOD("_set_texture_rotationd", "texture_rotation"), &Polygon2D::_set_texture_rotationd);
- ClassDB::bind_method(D_METHOD("_get_texture_rotationd"), &Polygon2D::_get_texture_rotationd);
+ ClassDB::bind_method(D_METHOD("set_texture_rotation_degrees", "texture_rotation"), &Polygon2D::set_texture_rotation_degrees);
+ ClassDB::bind_method(D_METHOD("get_texture_rotation_degrees"), &Polygon2D::get_texture_rotation_degrees);
ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Polygon2D::set_texture_scale);
ClassDB::bind_method(D_METHOD("get_texture_scale"), &Polygon2D::get_texture_scale);
@@ -377,7 +377,7 @@ void Polygon2D::_bind_methods() {
ADD_GROUP("Texture", "texture_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset"), "set_texture_offset", "get_texture_offset");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale"), "set_texture_scale", "get_texture_scale");
- ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation", PROPERTY_HINT_RANGE, "-1440,1440,0.1"), "_set_texture_rotationd", "_get_texture_rotationd");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation", PROPERTY_HINT_RANGE, "-1440,1440,0.1"), "set_texture_rotation_degrees", "get_texture_rotation_degrees");
ADD_GROUP("Invert", "invert_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert_enable"), "set_invert", "get_invert");
diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h
index 20c3324a50..d09e22f5ff 100644
--- a/scene/2d/polygon_2d.h
+++ b/scene/2d/polygon_2d.h
@@ -53,9 +53,6 @@ class Polygon2D : public Node2D {
mutable bool rect_cache_dirty;
mutable Rect2 item_rect;
- void _set_texture_rotationd(float p_rot);
- float _get_texture_rotationd() const;
-
protected:
void _notification(int p_what);
static void _bind_methods();
@@ -82,6 +79,9 @@ public:
void set_texture_rotation(float p_rot);
float get_texture_rotation() const;
+ void set_texture_rotation_degrees(float p_rot);
+ float get_texture_rotation_degrees() const;
+
void set_texture_scale(const Size2 &p_scale);
Size2 get_texture_scale() const;
@@ -99,11 +99,11 @@ public:
//editor stuff
- virtual void edit_set_pivot(const Point2 &p_pivot);
- virtual Point2 edit_get_pivot() const;
- virtual bool edit_has_pivot() const;
+ virtual void _edit_set_pivot(const Point2 &p_pivot);
+ virtual Point2 _edit_get_pivot() const;
+ virtual bool _edit_use_pivot() const;
- virtual Rect2 get_item_rect() const;
+ virtual Rect2 _edit_get_rect() const;
Polygon2D();
};
diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp
index cde665d422..1e729bc179 100644
--- a/scene/2d/position_2d.cpp
+++ b/scene/2d/position_2d.cpp
@@ -38,7 +38,7 @@ void Position2D::_draw_cross() {
draw_line(Point2(0, -10), Point2(0, +10), Color(0.5, 1, 0.5));
}
-Rect2 Position2D::get_item_rect() const {
+Rect2 Position2D::_edit_get_rect() const {
return Rect2(Point2(-10, -10), Size2(20, 20));
}
diff --git a/scene/2d/position_2d.h b/scene/2d/position_2d.h
index af54fb919a..5961e447df 100644
--- a/scene/2d/position_2d.h
+++ b/scene/2d/position_2d.h
@@ -42,7 +42,7 @@ protected:
void _notification(int p_what);
public:
- virtual Rect2 get_item_rect() const;
+ virtual Rect2 _edit_get_rect() const;
Position2D();
};
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp
index bf7c5a3ba4..d5fcda90d5 100644
--- a/scene/2d/screen_button.cpp
+++ b/scene/2d/screen_button.cpp
@@ -133,7 +133,7 @@ void TouchScreenButton::_notification(int p_what) {
return;
if (shape.is_valid()) {
Color draw_col = get_tree()->get_debug_collisions_color();
- Vector2 pos = shape_centered ? get_item_rect().size * 0.5f : Vector2();
+ Vector2 pos = shape_centered ? _edit_get_rect().size * 0.5f : Vector2();
draw_set_transform_matrix(get_canvas_transform().translated(pos));
shape->draw(get_canvas_item(), draw_col);
}
@@ -251,7 +251,7 @@ void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
bool TouchScreenButton::_is_point_inside(const Point2 &p_point) {
Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(p_point);
- Rect2 item_rect = get_item_rect();
+ Rect2 item_rect = _edit_get_rect();
bool touched = false;
bool check_rect = true;
@@ -322,13 +322,13 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
}
}
-Rect2 TouchScreenButton::get_item_rect() const {
+Rect2 TouchScreenButton::_edit_get_rect() const {
if (texture.is_null())
return Rect2(0, 0, 1, 1);
/*
if (texture.is_null())
- return CanvasItem::get_item_rect();
+ return CanvasItem::_edit_get_rect();
*/
return Rect2(Size2(), texture->get_size());
diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h
index 7647070b26..2e674c20b4 100644
--- a/scene/2d/screen_button.h
+++ b/scene/2d/screen_button.h
@@ -102,7 +102,7 @@ public:
bool is_pressed() const;
- Rect2 get_item_rect() const;
+ Rect2 _edit_get_rect() const;
TouchScreenButton();
};
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index c53faab5f9..df2265aae9 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -33,16 +33,16 @@
#include "scene/main/viewport.h"
#include "scene/scene_string_names.h"
-void Sprite::edit_set_pivot(const Point2 &p_pivot) {
+void Sprite::_edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
}
-Point2 Sprite::edit_get_pivot() const {
+Point2 Sprite::_edit_get_pivot() const {
return get_offset();
}
-bool Sprite::edit_has_pivot() const {
+bool Sprite::_edit_use_pivot() const {
return true;
}
@@ -257,13 +257,13 @@ int Sprite::get_hframes() const {
return hframes;
}
-Rect2 Sprite::get_item_rect() const {
+Rect2 Sprite::_edit_get_rect() const {
if (texture.is_null())
return Rect2(0, 0, 1, 1);
/*
if (texture.is_null())
- return CanvasItem::get_item_rect();
+ return CanvasItem::_edit_get_rect();
*/
Size2i s;
@@ -368,224 +368,3 @@ Sprite::Sprite() {
vframes = 1;
hframes = 1;
}
-
-//////////////////////////// VPSPRITE
-///
-///
-///
-
-#if 0
-void ViewportSprite::edit_set_pivot(const Point2& p_pivot) {
-
- set_offset(p_pivot);
-}
-
-Point2 ViewportSprite::edit_get_pivot() const {
-
- return get_offset();
-}
-bool ViewportSprite::edit_has_pivot() const {
-
- return true;
-}
-
-void ViewportSprite::_notification(int p_what) {
-
- switch(p_what) {
-
- case NOTIFICATION_ENTER_TREE: {
-
- if (!viewport_path.is_empty()) {
-
- Node *n = get_node(viewport_path);
- ERR_FAIL_COND(!n);
- Viewport *vp=Object::cast_to<Viewport>(n);
- ERR_FAIL_COND(!vp);
-
- Ref<RenderTargetTexture> rtt = vp->get_render_target_texture();
- texture=rtt;
- texture->connect("changed",this,"update");
- item_rect_changed();
- }
- } break;
- case NOTIFICATION_EXIT_TREE: {
-
- if (texture.is_valid()) {
-
- texture->disconnect("changed",this,"update");
- texture=Ref<Texture>();
- }
- } break;
- case NOTIFICATION_DRAW: {
-
- if (texture.is_null())
- return;
-
- RID ci = get_canvas_item();
-
- /*
- texture->draw(ci,Point2());
- break;
- */
-
- Size2i s;
- Rect2i src_rect;
-
- s = texture->get_size();
-
- src_rect.size=s;
-
- Point2 ofs=offset;
- if (centered)
- ofs-=s/2;
-
- if (OS::get_singleton()->get_use_pixel_snap()) {
- ofs=ofs.floor();
- }
- Rect2 dst_rect(ofs,s);
- texture->draw_rect_region(ci,dst_rect,src_rect,modulate);
-
- } break;
- }
-}
-
-void ViewportSprite::set_viewport_path(const NodePath& p_viewport) {
-
- viewport_path=p_viewport;
- update();
- if (!is_inside_tree())
- return;
-
- if (texture.is_valid()) {
- texture->disconnect("changed",this,"update");
- texture=Ref<Texture>();
- }
-
- if (viewport_path.is_empty())
- return;
-
-
- Node *n = get_node(viewport_path);
- ERR_FAIL_COND(!n);
- Viewport *vp=Object::cast_to<Viewport>(n);
- ERR_FAIL_COND(!vp);
-
- Ref<RenderTargetTexture> rtt = vp->get_render_target_texture();
- texture=rtt;
-
- if (texture.is_valid()) {
- texture->connect("changed",this,"update");
- }
-
- item_rect_changed();
-
-}
-
-NodePath ViewportSprite::get_viewport_path() const {
-
- return viewport_path;
-}
-
-void ViewportSprite::set_centered(bool p_center) {
-
- centered=p_center;
- update();
- item_rect_changed();
-}
-
-bool ViewportSprite::is_centered() const {
-
- return centered;
-}
-
-void ViewportSprite::set_offset(const Point2& p_offset) {
-
- offset=p_offset;
- update();
- item_rect_changed();
-}
-Point2 ViewportSprite::get_offset() const {
-
- return offset;
-}
-void ViewportSprite::set_modulate(const Color& p_color) {
-
- modulate=p_color;
- update();
-}
-
-Color ViewportSprite::get_modulate() const{
-
- return modulate;
-}
-
-
-Rect2 ViewportSprite::get_item_rect() const {
-
- if (texture.is_null())
- return Rect2(0,0,1,1);
- /*
- if (texture.is_null())
- return CanvasItem::get_item_rect();
- */
-
- Size2i s;
-
- s = texture->get_size();
- Point2 ofs=offset;
- if (centered)
- ofs-=s/2;
-
- if (s==Size2(0,0))
- s=Size2(1,1);
-
- return Rect2(ofs,s);
-}
-
-String ViewportSprite::get_configuration_warning() const {
-
- if (!has_node(viewport_path) || !Object::cast_to<Viewport>(get_node(viewport_path))) {
- return TTR("Path property must point to a valid Viewport node to work. Such Viewport must be set to 'render target' mode.");
- } else {
-
- Node *n = get_node(viewport_path);
- if (n) {
- Viewport *vp = Object::cast_to<Viewport>(n);
- if (!vp->is_set_as_render_target()) {
-
- return TTR("The Viewport set in the path property must be set as 'render target' in order for this sprite to work.");
- }
- }
- }
-
- return String();
-
-}
-
-void ViewportSprite::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("set_viewport_path","path"),&ViewportSprite::set_viewport_path);
- ClassDB::bind_method(D_METHOD("get_viewport_path"),&ViewportSprite::get_viewport_path);
-
- ClassDB::bind_method(D_METHOD("set_centered","centered"),&ViewportSprite::set_centered);
- ClassDB::bind_method(D_METHOD("is_centered"),&ViewportSprite::is_centered);
-
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&ViewportSprite::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&ViewportSprite::get_offset);
-
- ClassDB::bind_method(D_METHOD("set_modulate","modulate"),&ViewportSprite::set_modulate);
- ClassDB::bind_method(D_METHOD("get_modulate"),&ViewportSprite::get_modulate);
-
- ADD_PROPERTYNZ( PropertyInfo( Variant::NODE_PATH, "viewport"), "set_viewport_path","get_viewport_path");
- ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), "set_centered","is_centered");
- ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), "set_offset","get_offset");
- ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), "set_modulate","get_modulate");
-
-}
-
-ViewportSprite::ViewportSprite() {
-
- centered=true;
- modulate=Color(1,1,1,1);
-}
-#endif
diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h
index 64d30325f2..1bef73c0a5 100644
--- a/scene/2d/sprite.h
+++ b/scene/2d/sprite.h
@@ -62,9 +62,10 @@ protected:
virtual void _validate_property(PropertyInfo &property) const;
public:
- virtual void edit_set_pivot(const Point2 &p_pivot);
- virtual Point2 edit_get_pivot() const;
- virtual bool edit_has_pivot() const;
+ virtual void _edit_set_pivot(const Point2 &p_pivot);
+ virtual Point2 _edit_get_pivot() const;
+ virtual bool _edit_use_pivot() const;
+ virtual Rect2 _edit_get_rect() const;
void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
@@ -102,53 +103,7 @@ public:
void set_hframes(int p_amount);
int get_hframes() const;
- virtual Rect2 get_item_rect() const;
-
Sprite();
};
-#if 0
-class ViewportSprite : public Node2D {
-
- GDCLASS( ViewportSprite, Node2D );
-
- Ref<Texture> texture;
- NodePath viewport_path;
-
- bool centered;
- Point2 offset;
- Color modulate;
-
-protected:
-
- void _notification(int p_what);
-
- static void _bind_methods();
-
-public:
-
- virtual void edit_set_pivot(const Point2& p_pivot);
- virtual Point2 edit_get_pivot() const;
- virtual bool edit_has_pivot() const;
-
- void set_viewport_path(const NodePath& p_viewport);
- NodePath get_viewport_path() const;
-
- void set_centered(bool p_center);
- bool is_centered() const;
-
- void set_offset(const Point2& p_offset);
- Point2 get_offset() const;
-
- void set_modulate(const Color& p_color);
- Color get_modulate() const;
-
- virtual Rect2 get_item_rect() const;
-
- virtual String get_configuration_warning() const;
-
- ViewportSprite();
-};
-
-#endif
#endif // SPRITE_H
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 4286d88ab1..f067b5a187 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -448,21 +448,20 @@ void TileMap::_update_dirty_quadrants() {
if (r == Rect2()) {
tex->draw_rect(canvas_item, rect, false, modulate, c.transpose, normal_map);
} else {
- tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map);
+ tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose, normal_map, clip_uv);
}
Vector<TileSet::ShapeData> shapes = tile_set->tile_get_shapes(c.id);
for (int i = 0; i < shapes.size(); i++) {
-
Ref<Shape2D> shape = shapes[i].shape;
if (shape.is_valid()) {
Transform2D xform;
xform.set_origin(offset.floor());
- _fix_cell_transform(xform, c, center_ofs, s);
+ Vector2 shape_ofs = tile_set->tile_get_shape_offset(c.id, i);
- xform *= shapes[i].shape_transform;
+ _fix_cell_transform(xform, c, shape_ofs + center_ofs, s);
if (debug_canvas_item.is_valid()) {
vs->canvas_item_add_set_transform(debug_canvas_item, xform);
@@ -587,7 +586,9 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons
xform.set_origin(q.pos);
//q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
- q.body = Physics2DServer::get_singleton()->body_create(use_kinematic ? Physics2DServer::BODY_MODE_KINEMATIC : Physics2DServer::BODY_MODE_STATIC);
+ q.body = Physics2DServer::get_singleton()->body_create();
+ Physics2DServer::get_singleton()->body_set_mode(q.body, use_kinematic ? Physics2DServer::BODY_MODE_KINEMATIC : Physics2DServer::BODY_MODE_STATIC);
+
Physics2DServer::get_singleton()->body_attach_object_instance_id(q.body, get_instance_id());
Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer);
Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask);
@@ -882,7 +883,7 @@ PoolVector<int> TileMap::_get_tile_data() const {
return data;
}
-Rect2 TileMap::get_item_rect() const {
+Rect2 TileMap::_edit_get_rect() const {
const_cast<TileMap *>(this)->_update_dirty_quadrants();
return rect_cache;
@@ -1234,6 +1235,21 @@ void TileMap::set_light_mask(int p_light_mask) {
}
}
+void TileMap::set_clip_uv(bool p_enable) {
+
+ if (clip_uv == p_enable)
+ return;
+
+ _clear_quadrants();
+ clip_uv = p_enable;
+ _recreate_quadrants();
+}
+
+bool TileMap::get_clip_uv() const {
+
+ return clip_uv;
+}
+
void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
@@ -1266,6 +1282,9 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_center_y", "enable"), &TileMap::set_center_y);
ClassDB::bind_method(D_METHOD("get_center_y"), &TileMap::get_center_y);
+ ClassDB::bind_method(D_METHOD("set_clip_uv", "enable"), &TileMap::set_clip_uv);
+ ClassDB::bind_method(D_METHOD("get_clip_uv"), &TileMap::get_clip_uv);
+
ClassDB::bind_method(D_METHOD("set_y_sort_mode", "enable"), &TileMap::set_y_sort_mode);
ClassDB::bind_method(D_METHOD("is_y_sort_mode_enabled"), &TileMap::is_y_sort_mode_enabled);
@@ -1327,6 +1346,7 @@ void TileMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled"), "set_half_offset", "get_half_offset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv");
ADD_GROUP("Collision", "collision_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_kinematic", PROPERTY_HINT_NONE, ""), "set_collision_use_kinematic", "get_collision_use_kinematic");
@@ -1377,6 +1397,7 @@ TileMap::TileMap() {
navigation = NULL;
y_sort_mode = false;
occluder_light_mask = 1;
+ clip_uv = false;
fp_adjust = 0.00001;
tile_origin = TILE_ORIGIN_TOP_LEFT;
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index c9d14e09d1..9e14ec838a 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -161,6 +161,7 @@ private:
bool used_size_cache_dirty;
bool quadrant_order_dirty;
bool y_sort_mode;
+ bool clip_uv;
float fp_adjust;
float friction;
float bounce;
@@ -228,7 +229,7 @@ public:
void set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false);
int get_cellv(const Vector2 &p_pos) const;
- Rect2 get_item_rect() const;
+ Rect2 _edit_get_rect() const;
void set_collision_layer(uint32_t p_layer);
uint32_t get_collision_layer() const;
@@ -285,6 +286,9 @@ public:
virtual void set_use_parent_material(bool p_use_parent_material);
+ void set_clip_uv(bool p_enable);
+ bool get_clip_uv() const;
+
void clear();
TileMap();
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index b0fd57baf5..298bc2649e 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -83,7 +83,7 @@ void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) {
_change_notify("rect");
}
-Rect2 VisibilityNotifier2D::get_item_rect() const {
+Rect2 VisibilityNotifier2D::_edit_get_rect() const {
return rect;
}
diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h
index ee5152978b..6e06833912 100644
--- a/scene/2d/visibility_notifier_2d.h
+++ b/scene/2d/visibility_notifier_2d.h
@@ -54,13 +54,13 @@ protected:
static void _bind_methods();
public:
+ virtual Rect2 _edit_get_rect() const;
+
void set_rect(const Rect2 &p_rect);
Rect2 get_rect() const;
bool is_on_screen() const;
- virtual Rect2 get_item_rect() const;
-
VisibilityNotifier2D();
};