summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/canvas_item.cpp6
-rw-r--r--scene/2d/canvas_item.h4
-rw-r--r--scene/2d/node_2d.cpp46
-rw-r--r--scene/2d/node_2d.h12
-rw-r--r--scene/2d/physics_body_2d.cpp3
-rw-r--r--scene/2d/polygon_2d.cpp10
-rw-r--r--scene/2d/polygon_2d.h6
-rw-r--r--scene/2d/tile_map.cpp31
-rw-r--r--scene/2d/tile_map.h4
9 files changed, 68 insertions, 54 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index b41ba7f590..fa45c61f68 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);
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 1afbd150a2..1a043c204f 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();
};
@@ -248,7 +250,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);
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index e62b59dd4d..c562a4652d 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -65,7 +65,7 @@ void Node2D::edit_set_state(const Variant &p_state) {
_scale = state[2];
_update_transform();
_change_notify("rotation");
- _change_notify("rotation_deg");
+ _change_notify("rotation_degrees");
_change_notify("scale");
_change_notify("position");
}
@@ -106,7 +106,7 @@ void Node2D::edit_rotate(float p_rot) {
angle += p_rot;
_update_transform();
_change_notify("rotation");
- _change_notify("rotation_deg");
+ _change_notify("rotation_degrees");
}
void Node2D::_update_xform_values() {
@@ -147,22 +147,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 +174,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();
@@ -299,12 +287,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 +398,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 +419,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);
@@ -462,13 +446,13 @@ void Node2D::_bind_methods() {
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..eca1e96c82 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:
@@ -70,7 +66,7 @@ public:
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,12 +78,12 @@ 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;
@@ -95,7 +91,7 @@ public:
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/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index f0ee64a53f..1287a800e3 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);
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 197c74352e..b5b5445684 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -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..0c2c049c18 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;
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 4286d88ab1..dd4270ab26 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);
@@ -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..706b87cec3 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;
@@ -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();