summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/canvas_item.cpp1
-rw-r--r--scene/2d/collision_object_2d.cpp7
-rw-r--r--scene/2d/cpu_particles_2d.cpp23
-rw-r--r--scene/2d/cpu_particles_2d.h4
-rw-r--r--scene/2d/line_2d.cpp101
-rw-r--r--scene/2d/line_2d.h5
-rw-r--r--scene/2d/line_builder.cpp120
-rw-r--r--scene/2d/line_builder.h1
-rw-r--r--scene/2d/navigation_2d.cpp1
-rw-r--r--scene/2d/particles_2d.cpp1
-rw-r--r--scene/2d/physics_body_2d.cpp2
-rw-r--r--scene/2d/tile_map.cpp361
-rw-r--r--scene/2d/tile_map.h23
13 files changed, 510 insertions, 140 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 78e98deb93..23f6404e3e 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -1074,6 +1074,7 @@ Vector2 CanvasItem::make_canvas_position_local(const Vector2 &screen_point) cons
Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const {
+ ERR_FAIL_COND_V(p_event.is_null(), p_event);
ERR_FAIL_COND_V(!is_inside_tree(), p_event);
return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse());
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index 375375285d..36c88e395a 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -218,12 +218,13 @@ void CollisionObject2D::shape_owner_set_transform(uint32_t p_owner, const Transf
ERR_FAIL_COND(!shapes.has(p_owner));
ShapeData &sd = shapes[p_owner];
+
sd.xform = p_transform;
for (int i = 0; i < sd.shapes.size(); i++) {
if (area) {
- Physics2DServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, p_transform);
+ Physics2DServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, sd.xform);
} else {
- Physics2DServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, p_transform);
+ Physics2DServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, sd.xform);
}
}
}
@@ -387,7 +388,7 @@ String CollisionObject2D::get_configuration_warning() const {
String warning = Node2D::get_configuration_warning();
if (shapes.empty()) {
- if (warning == String()) {
+ if (!warning.empty()) {
warning += "\n";
}
warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape.");
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index faa0a08d10..2091085420 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -262,6 +262,16 @@ void CPUParticles2D::restart() {
}
}
+void CPUParticles2D::set_direction(Vector2 p_direction) {
+
+ direction = p_direction;
+}
+
+Vector2 CPUParticles2D::get_direction() const {
+
+ return direction;
+}
+
void CPUParticles2D::set_spread(float p_spread) {
spread = p_spread;
@@ -631,7 +641,7 @@ void CPUParticles2D::_particles_process(float p_delta) {
p.hue_rot_rand = Math::randf();
p.anim_offset_rand = Math::randf();
- float angle1_rad = (Math::randf() * 2.0 - 1.0) * Math_PI * spread / 180.0;
+ float angle1_rad = Math::atan2(direction.y, direction.x) + (Math::randf() * 2.0 - 1.0) * Math_PI * spread / 180.0;
Vector2 rot = Vector2(Math::cos(angle1_rad), Math::sin(angle1_rad));
p.velocity = rot * parameters[PARAM_INITIAL_LINEAR_VELOCITY] * Math::lerp(1.0f, float(Math::randf()), randomness[PARAM_INITIAL_LINEAR_VELOCITY]);
@@ -1121,6 +1131,8 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) {
if (material.is_null())
return;
+ Vector3 dir = material->get_direction();
+ set_direction(Vector2(dir.x, dir.y));
set_spread(material->get_spread());
set_flatness(material->get_flatness());
@@ -1226,6 +1238,9 @@ void CPUParticles2D::_bind_methods() {
////////////////////////////////
+ ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles2D::set_direction);
+ ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles2D::get_direction);
+
ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles2D::set_spread);
ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles2D::get_spread);
@@ -1284,7 +1299,8 @@ void CPUParticles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "emission_colors"), "set_emission_colors", "get_emission_colors");
ADD_GROUP("Flags", "flag_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flag_align_y"), "set_particle_flag", "get_particle_flag", FLAG_ALIGN_Y_TO_VELOCITY);
- ADD_GROUP("Spread", "");
+ ADD_GROUP("Direction", "");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "direction"), "set_direction", "get_direction");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "spread", PROPERTY_HINT_RANGE, "0,180,0.01"), "set_spread", "get_spread");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "flatness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_flatness", "get_flatness");
ADD_GROUP("Gravity", "");
@@ -1392,6 +1408,7 @@ CPUParticles2D::CPUParticles2D() {
set_draw_order(DRAW_ORDER_INDEX);
set_speed_scale(1);
+ set_direction(Vector2(1, 0));
set_spread(45);
set_flatness(0);
set_param(PARAM_INITIAL_LINEAR_VELOCITY, 0);
@@ -1410,7 +1427,7 @@ CPUParticles2D::CPUParticles2D() {
set_emission_sphere_radius(1);
set_emission_rect_extents(Vector2(1, 1));
- set_gravity(Vector2(0, 98.8));
+ set_gravity(Vector2(0, 98));
for (int i = 0; i < PARAM_MAX; i++) {
set_param_randomness(Parameter(i), 0);
diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h
index 813f5ddc6e..8613a185b4 100644
--- a/scene/2d/cpu_particles_2d.h
+++ b/scene/2d/cpu_particles_2d.h
@@ -153,6 +153,7 @@ private:
////////
+ Vector2 direction;
float spread;
float flatness;
@@ -234,6 +235,9 @@ public:
///////////////////
+ void set_direction(Vector2 p_direction);
+ Vector2 get_direction() const;
+
void set_spread(float p_spread);
float get_spread() const;
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 4488dc501c..ad405fabbb 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -44,6 +44,7 @@ Line2D::Line2D() {
_end_cap_mode = LINE_CAP_NONE;
_width = 10;
_default_color = Color(0.4, 0.5, 1);
+ _texture_mode = LINE_TEXTURE_NONE;
_sharp_limit = 2.f;
_round_precision = 8;
}
@@ -83,10 +84,10 @@ void Line2D::set_points(const PoolVector<Vector2> &p_points) {
update();
}
-void Line2D::set_width(float width) {
- if (width < 0.0)
- width = 0.0;
- _width = width;
+void Line2D::set_width(float p_width) {
+ if (p_width < 0.0)
+ p_width = 0.0;
+ _width = p_width;
update();
}
@@ -94,12 +95,32 @@ float Line2D::get_width() const {
return _width;
}
+void Line2D::set_curve(const Ref<Curve> &p_curve) {
+ // Cleanup previous connection if any
+ if (_curve.is_valid()) {
+ _curve->disconnect(CoreStringNames::get_singleton()->changed, this, "_curve_changed");
+ }
+
+ _curve = p_curve;
+
+ // Connect to the curve so the line will update when it is changed
+ if (_curve.is_valid()) {
+ _curve->connect(CoreStringNames::get_singleton()->changed, this, "_curve_changed");
+ }
+
+ update();
+}
+
+Ref<Curve> Line2D::get_curve() const {
+ return _curve;
+}
+
PoolVector<Vector2> Line2D::get_points() const {
return _points;
}
-void Line2D::set_point_position(int i, Vector2 pos) {
- _points.set(i, pos);
+void Line2D::set_point_position(int i, Vector2 p_pos) {
+ _points.set(i, p_pos);
update();
}
@@ -120,11 +141,11 @@ void Line2D::clear_points() {
}
}
-void Line2D::add_point(Vector2 pos, int atpos) {
- if (atpos < 0 || _points.size() < atpos) {
- _points.append(pos);
+void Line2D::add_point(Vector2 p_pos, int p_atpos) {
+ if (p_atpos < 0 || _points.size() < p_atpos) {
+ _points.append(p_pos);
} else {
- _points.insert(atpos, pos);
+ _points.insert(p_atpos, p_pos);
}
update();
}
@@ -134,8 +155,8 @@ void Line2D::remove_point(int i) {
update();
}
-void Line2D::set_default_color(Color color) {
- _default_color = color;
+void Line2D::set_default_color(Color p_color) {
+ _default_color = p_color;
update();
}
@@ -143,18 +164,18 @@ Color Line2D::get_default_color() const {
return _default_color;
}
-void Line2D::set_gradient(const Ref<Gradient> &gradient) {
+void Line2D::set_gradient(const Ref<Gradient> &p_gradient) {
// Cleanup previous connection if any
if (_gradient.is_valid()) {
- (**_gradient).disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
+ _gradient->disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
- _gradient = gradient;
+ _gradient = p_gradient;
// Connect to the gradient so the line will update when the ColorRamp is changed
if (_gradient.is_valid()) {
- (**_gradient).connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
+ _gradient->connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
update();
@@ -164,8 +185,8 @@ Ref<Gradient> Line2D::get_gradient() const {
return _gradient;
}
-void Line2D::set_texture(const Ref<Texture> &texture) {
- _texture = texture;
+void Line2D::set_texture(const Ref<Texture> &p_texture) {
+ _texture = p_texture;
update();
}
@@ -173,8 +194,8 @@ Ref<Texture> Line2D::get_texture() const {
return _texture;
}
-void Line2D::set_texture_mode(const LineTextureMode mode) {
- _texture_mode = mode;
+void Line2D::set_texture_mode(const LineTextureMode p_mode) {
+ _texture_mode = p_mode;
update();
}
@@ -182,8 +203,8 @@ Line2D::LineTextureMode Line2D::get_texture_mode() const {
return _texture_mode;
}
-void Line2D::set_joint_mode(LineJointMode mode) {
- _joint_mode = mode;
+void Line2D::set_joint_mode(LineJointMode p_mode) {
+ _joint_mode = p_mode;
update();
}
@@ -191,8 +212,8 @@ Line2D::LineJointMode Line2D::get_joint_mode() const {
return _joint_mode;
}
-void Line2D::set_begin_cap_mode(LineCapMode mode) {
- _begin_cap_mode = mode;
+void Line2D::set_begin_cap_mode(LineCapMode p_mode) {
+ _begin_cap_mode = p_mode;
update();
}
@@ -200,8 +221,8 @@ Line2D::LineCapMode Line2D::get_begin_cap_mode() const {
return _begin_cap_mode;
}
-void Line2D::set_end_cap_mode(LineCapMode mode) {
- _end_cap_mode = mode;
+void Line2D::set_end_cap_mode(LineCapMode p_mode) {
+ _end_cap_mode = p_mode;
update();
}
@@ -217,10 +238,10 @@ void Line2D::_notification(int p_what) {
}
}
-void Line2D::set_sharp_limit(float limit) {
- if (limit < 0.f)
- limit = 0.f;
- _sharp_limit = limit;
+void Line2D::set_sharp_limit(float p_limit) {
+ if (p_limit < 0.f)
+ p_limit = 0.f;
+ _sharp_limit = p_limit;
update();
}
@@ -228,10 +249,10 @@ float Line2D::get_sharp_limit() const {
return _sharp_limit;
}
-void Line2D::set_round_precision(int precision) {
- if (precision < 1)
- precision = 1;
- _round_precision = precision;
+void Line2D::set_round_precision(int p_precision) {
+ if (p_precision < 1)
+ p_precision = 1;
+ _round_precision = p_precision;
update();
}
@@ -267,10 +288,11 @@ void Line2D::_draw() {
lb.round_precision = _round_precision;
lb.sharp_limit = _sharp_limit;
lb.width = _width;
+ lb.curve = *_curve;
RID texture_rid;
if (_texture.is_valid()) {
- texture_rid = (**_texture).get_rid();
+ texture_rid = _texture->get_rid();
lb.tile_aspect = _texture->get_size().aspect();
}
@@ -311,6 +333,10 @@ void Line2D::_gradient_changed() {
update();
}
+void Line2D::_curve_changed() {
+ update();
+}
+
// static
void Line2D::_bind_methods() {
@@ -330,6 +356,9 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_width", "width"), &Line2D::set_width);
ClassDB::bind_method(D_METHOD("get_width"), &Line2D::get_width);
+ ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Line2D::set_curve);
+ ClassDB::bind_method(D_METHOD("get_curve"), &Line2D::get_curve);
+
ClassDB::bind_method(D_METHOD("set_default_color", "color"), &Line2D::set_default_color);
ClassDB::bind_method(D_METHOD("get_default_color"), &Line2D::get_default_color);
@@ -359,6 +388,7 @@ void Line2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "default_color"), "set_default_color", "get_default_color");
ADD_GROUP("Fill", "");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_gradient", "get_gradient");
@@ -385,4 +415,5 @@ void Line2D::_bind_methods() {
BIND_ENUM_CONSTANT(LINE_TEXTURE_STRETCH);
ClassDB::bind_method(D_METHOD("_gradient_changed"), &Line2D::_gradient_changed);
+ ClassDB::bind_method(D_METHOD("_curve_changed"), &Line2D::_curve_changed);
}
diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h
index 11be5055d4..14afa463ba 100644
--- a/scene/2d/line_2d.h
+++ b/scene/2d/line_2d.h
@@ -78,6 +78,9 @@ public:
void set_width(float width);
float get_width() const;
+ void set_curve(const Ref<Curve> &curve);
+ Ref<Curve> get_curve() const;
+
void set_default_color(Color color);
Color get_default_color() const;
@@ -113,6 +116,7 @@ protected:
private:
void _gradient_changed();
+ void _curve_changed();
private:
PoolVector<Vector2> _points;
@@ -120,6 +124,7 @@ private:
LineCapMode _begin_cap_mode;
LineCapMode _end_cap_mode;
float _width;
+ Ref<Curve> _curve;
Color _default_color;
Ref<Gradient> _gradient;
Ref<Texture> _texture;
diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp
index eb09d3c9d3..9fe5fb98b6 100644
--- a/scene/2d/line_builder.cpp
+++ b/scene/2d/line_builder.cpp
@@ -95,6 +95,7 @@ static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) {
LineBuilder::LineBuilder() {
joint_mode = Line2D::LINE_JOINT_SHARP;
width = 10;
+ curve = NULL;
default_color = Color(0.4, 0.5, 1);
gradient = NULL;
sharp_limit = 2.f;
@@ -136,8 +137,8 @@ void LineBuilder::build() {
Vector2 pos1 = points[1];
Vector2 f0 = (pos1 - pos0).normalized();
Vector2 u0 = rotate90(f0);
- Vector2 pos_up0 = pos0 + u0 * hw;
- Vector2 pos_down0 = pos0 - u0 * hw;
+ Vector2 pos_up0 = pos0;
+ Vector2 pos_down0 = pos0;
Color color0;
Color color1;
@@ -145,12 +146,30 @@ void LineBuilder::build() {
float current_distance0 = 0.f;
float current_distance1 = 0.f;
float total_distance = 0.f;
+ float width_factor = 1.f;
_interpolate_color = gradient != NULL;
+ bool retrieve_curve = curve != NULL;
bool distance_required = _interpolate_color ||
+ retrieve_curve ||
texture_mode == Line2D::LINE_TEXTURE_TILE ||
texture_mode == Line2D::LINE_TEXTURE_STRETCH;
- if (distance_required)
+ if (distance_required) {
total_distance = calculate_total_distance(points);
+ //Ajust totalDistance.
+ // The line's outer length will be a little higher due to begin and end caps
+ if (begin_cap_mode == Line2D::LINE_CAP_BOX || begin_cap_mode == Line2D::LINE_CAP_ROUND) {
+ if (retrieve_curve)
+ total_distance += width * curve->interpolate_baked(0.f) * 0.5f;
+ else
+ total_distance += width * 0.5f;
+ }
+ if (end_cap_mode == Line2D::LINE_CAP_BOX || end_cap_mode == Line2D::LINE_CAP_ROUND) {
+ if (retrieve_curve)
+ total_distance += width * curve->interpolate_baked(1.f) * 0.5f;
+ else
+ total_distance += width * 0.5f;
+ }
+ }
if (_interpolate_color)
color0 = gradient->get_color(0);
else
@@ -159,22 +178,28 @@ void LineBuilder::build() {
float uvx0 = 0.f;
float uvx1 = 0.f;
+ if (retrieve_curve)
+ width_factor = curve->interpolate_baked(0.f);
+
+ pos_up0 += u0 * hw * width_factor;
+ pos_down0 -= u0 * hw * width_factor;
+
// Begin cap
if (begin_cap_mode == Line2D::LINE_CAP_BOX) {
// Push back first vertices a little bit
- pos_up0 -= f0 * hw;
- pos_down0 -= f0 * hw;
- // The line's outer length will be a little higher due to begin and end caps
- total_distance += width;
- current_distance0 += hw;
+ pos_up0 -= f0 * hw * width_factor;
+ pos_down0 -= f0 * hw * width_factor;
+
+ current_distance0 += hw * width_factor;
current_distance1 = current_distance0;
} else if (begin_cap_mode == Line2D::LINE_CAP_ROUND) {
if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
- uvx0 = 0.5f / tile_aspect;
+ uvx0 = width_factor * 0.5f / tile_aspect;
+ } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
+ uvx0 = width * width_factor / total_distance;
}
- new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, fmin(uvx0 * 2, 1.f), 1.f));
- total_distance += width;
- current_distance0 += hw;
+ new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, uvx0 * 2, 1.f));
+ current_distance0 += hw * width_factor;
current_distance1 = current_distance0;
}
@@ -206,13 +231,23 @@ void LineBuilder::build() {
const float dp = u0.dot(f1);
const Orientation orientation = (dp > 0.f ? UP : DOWN);
+ if (distance_required) {
+ current_distance1 += pos0.distance_to(pos1);
+ }
+ if (_interpolate_color) {
+ color1 = gradient->get_color_at_offset(current_distance1 / total_distance);
+ }
+ if (retrieve_curve) {
+ width_factor = curve->interpolate_baked(current_distance1 / total_distance);
+ }
+
Vector2 inner_normal0, inner_normal1;
if (orientation == UP) {
- inner_normal0 = u0 * hw;
- inner_normal1 = u1 * hw;
+ inner_normal0 = u0 * hw * width_factor;
+ inner_normal1 = u1 * hw * width_factor;
} else {
- inner_normal0 = -u0 * hw;
- inner_normal1 = -u1 * hw;
+ inner_normal0 = -u0 * hw * width_factor;
+ inner_normal1 = -u1 * hw * width_factor;
}
/*
@@ -259,7 +294,8 @@ void LineBuilder::build() {
Vector2 pos_up1, pos_down1;
if (intersection_result == SEGMENT_INTERSECT) {
// Fallback on bevel if sharp angle is too high (because it would produce very long miters)
- if (current_joint_mode == Line2D::LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / hw_sq > sharp_limit_sq) {
+ float width_factor_sq = width_factor * width_factor;
+ if (current_joint_mode == Line2D::LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / (hw_sq * width_factor_sq) > sharp_limit_sq) {
current_joint_mode = Line2D::LINE_JOINT_BEVEL;
}
if (current_joint_mode == Line2D::LINE_JOINT_SHARP) {
@@ -271,9 +307,9 @@ void LineBuilder::build() {
// Bevel or round
if (orientation == UP) {
pos_up1 = corner_pos_up;
- pos_down1 = pos1 - u0 * hw;
+ pos_down1 = pos1 - u0 * hw * width_factor;
} else {
- pos_up1 = pos1 + u0 * hw;
+ pos_up1 = pos1 + u0 * hw * width_factor;
pos_down1 = corner_pos_down;
}
}
@@ -289,12 +325,6 @@ void LineBuilder::build() {
// Add current line body quad
// Triangles are clockwise
- if (distance_required) {
- current_distance1 += pos0.distance_to(pos1);
- }
- if (_interpolate_color) {
- color1 = gradient->get_color_at_offset(current_distance1 / total_distance);
- }
if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
uvx1 = current_distance1 / (width * tile_aspect);
} else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
@@ -315,15 +345,15 @@ void LineBuilder::build() {
} else {
if (orientation == UP) {
pos_up0 = corner_pos_up;
- pos_down0 = pos1 - u1 * hw;
+ pos_down0 = pos1 - u1 * hw * width_factor;
} else {
- pos_up0 = pos1 + u1 * hw;
+ pos_up0 = pos1 + u1 * hw * width_factor;
pos_down0 = corner_pos_down;
}
}
} else {
- pos_up0 = pos1 + u1 * hw;
- pos_down0 = pos1 - u1 * hw;
+ pos_up0 = pos1 + u1 * hw * width_factor;
+ pos_down0 = pos1 - u1 * hw * width_factor;
}
// From this point, bu0 and bd0 concern the next segment
@@ -362,26 +392,28 @@ void LineBuilder::build() {
strip_begin(pos_up0, pos_down0, color1, uvx1);
}
}
-
// Last (or only) segment
-
pos1 = points[points.size() - 1];
- Vector2 pos_up1 = pos1 + u0 * hw;
- Vector2 pos_down1 = pos1 - u0 * hw;
-
- // End cap (box)
- if (end_cap_mode == Line2D::LINE_CAP_BOX) {
- pos_up1 += f0 * hw;
- pos_down1 += f0 * hw;
- }
-
if (distance_required) {
current_distance1 += pos0.distance_to(pos1);
}
if (_interpolate_color) {
color1 = gradient->get_color(gradient->get_points_count() - 1);
}
+ if (retrieve_curve) {
+ width_factor = curve->interpolate_baked(1.f);
+ }
+
+ Vector2 pos_up1 = pos1 + u0 * hw * width_factor;
+ Vector2 pos_down1 = pos1 - u0 * hw * width_factor;
+
+ // End cap (box)
+ if (end_cap_mode == Line2D::LINE_CAP_BOX) {
+ pos_up1 += f0 * hw * width_factor;
+ pos_down1 += f0 * hw * width_factor;
+ }
+
if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
uvx1 = current_distance1 / (width * tile_aspect);
} else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
@@ -394,7 +426,13 @@ void LineBuilder::build() {
if (end_cap_mode == Line2D::LINE_CAP_ROUND) {
// Note: color is not used in case we don't interpolate...
Color color = _interpolate_color ? gradient->get_color(gradient->get_points_count() - 1) : Color(0, 0, 0);
- new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f / tile_aspect, 0.f, 1.0f / tile_aspect, 1.f));
+ float dist = 0;
+ if (texture_mode == Line2D::LINE_TEXTURE_TILE) {
+ dist = width_factor / tile_aspect;
+ } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) {
+ dist = width * width_factor / total_distance;
+ }
+ new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f * dist, 0.f, dist, 1.f));
}
}
diff --git a/scene/2d/line_builder.h b/scene/2d/line_builder.h
index b961385e33..91b4518f9b 100644
--- a/scene/2d/line_builder.h
+++ b/scene/2d/line_builder.h
@@ -45,6 +45,7 @@ public:
Line2D::LineCapMode begin_cap_mode;
Line2D::LineCapMode end_cap_mode;
float width;
+ Curve *curve;
Color default_color;
Gradient *gradient;
Line2D::LineTextureMode texture_mode;
diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp
index 72b5f2fb12..f644db462b 100644
--- a/scene/2d/navigation_2d.cpp
+++ b/scene/2d/navigation_2d.cpp
@@ -92,7 +92,6 @@ void Navigation2D::_navpoly_link(int p_id) {
if (!valid) {
nm.polygons.pop_back();
ERR_CONTINUE(!valid);
- continue;
}
p.center = center / plen;
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 7759897420..93c12f0103 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -410,6 +410,7 @@ Particles2D::Particles2D() {
particles = VS::get_singleton()->particles_create();
+ one_shot = false; // Needed so that set_emitting doesn't access uninitialized values
set_emitting(true);
set_one_shot(false);
set_amount(8);
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 2bd9e5e2a2..95acf13fad 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1541,7 +1541,7 @@ Vector2 KinematicCollision2D::get_remainder() const {
return collision.remainder;
}
Object *KinematicCollision2D::get_local_shape() const {
- ERR_FAIL_COND_V(!owner, NULL);
+ if (!owner) return NULL;
uint32_t ownerid = owner->shape_find_owner(collision.local_shape);
return owner->shape_owner_get_owner(ownerid);
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index b3b6f3175d..22bc0e44e6 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -30,9 +30,11 @@
#include "tile_map.h"
+#include "collision_object_2d.h"
#include "core/io/marshalls.h"
#include "core/method_bind_ext.gen.inc"
#include "core/os/os.h"
+#include "scene/2d/area_2d.h"
#include "servers/physics_2d_server.h"
int TileMap::_get_quadrant_size() const {
@@ -60,14 +62,21 @@ void TileMap::_notification(int p_what) {
c = Object::cast_to<Node2D>(c->get_parent());
}
+ if (use_parent) {
+ _clear_quadrants();
+ collision_parent = Object::cast_to<CollisionObject2D>(get_parent());
+ }
+
pending_update = true;
_recreate_quadrants();
update_dirty_quadrants();
RID space = get_world_2d()->get_space();
_update_quadrant_transform();
_update_quadrant_space(space);
+ update_configuration_warning();
} break;
+
case NOTIFICATION_EXIT_TREE: {
_update_quadrant_space(RID());
@@ -82,30 +91,46 @@ void TileMap::_notification(int p_what) {
q.navpoly_ids.clear();
}
+ if (collision_parent) {
+ collision_parent->remove_shape_owner(q.shape_owner_id);
+ q.shape_owner_id = -1;
+ }
+
for (Map<PosKey, Quadrant::Occluder>::Element *F = q.occluder_instances.front(); F; F = F->next()) {
VS::get_singleton()->free(F->get().id);
}
q.occluder_instances.clear();
}
+ collision_parent = NULL;
navigation = NULL;
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
//move stuff
_update_quadrant_transform();
} break;
+ case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
+
+ if (use_parent) {
+ _recreate_quadrants();
+ }
+
+ } break;
}
}
void TileMap::_update_quadrant_space(const RID &p_space) {
- for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
+ if (!use_parent) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q = E->get();
- Physics2DServer::get_singleton()->body_set_space(q.body, p_space);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_space(q.body, p_space);
+ }
}
}
@@ -116,6 +141,10 @@ void TileMap::_update_quadrant_transform() {
Transform2D global_transform = get_global_transform();
+ Transform2D local_transform;
+ if (collision_parent)
+ local_transform = get_transform();
+
Transform2D nav_rel;
if (navigation)
nav_rel = get_relative_transform_to_parent(navigation);
@@ -125,8 +154,11 @@ void TileMap::_update_quadrant_transform() {
Quadrant &q = E->get();
Transform2D xform;
xform.set_origin(q.pos);
- xform = global_transform * xform;
- Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform);
+
+ if (!use_parent) {
+ xform = global_transform * xform;
+ Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform);
+ }
if (navigation) {
for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) {
@@ -202,6 +234,25 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const
Size2 s = p_sc;
Vector2 offset = p_offset;
+ if (compatibility_mode && !centered_textures) {
+
+ if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
+ offset.y += cell_size.y;
+ } else if (tile_origin == TILE_ORIGIN_CENTER) {
+ offset += cell_size / 2;
+ }
+
+ if (s.y > s.x) {
+ if ((p_cell.flip_h && (p_cell.flip_v || p_cell.transpose)) || (p_cell.flip_v && !p_cell.transpose)) {
+ offset.y += s.y - s.x;
+ }
+ } else if (s.y < s.x) {
+ if ((p_cell.flip_v && (p_cell.flip_h || p_cell.transpose)) || (p_cell.flip_h && !p_cell.transpose)) {
+ offset.x += s.x - s.y;
+ }
+ }
+ }
+
if (p_cell.transpose) {
SWAP(xform.elements[0].x, xform.elements[0].y);
SWAP(xform.elements[1].x, xform.elements[1].y);
@@ -212,19 +263,67 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const
if (p_cell.flip_h) {
xform.elements[0].x = -xform.elements[0].x;
xform.elements[1].x = -xform.elements[1].x;
- offset.x = s.x - offset.x;
+ if (compatibility_mode && !centered_textures) {
+ if (tile_origin == TILE_ORIGIN_TOP_LEFT || tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
+ offset.x = s.x - offset.x;
+ } else if (tile_origin == TILE_ORIGIN_CENTER) {
+ offset.x = s.x - offset.x / 2;
+ }
+ } else {
+ offset.x = s.x - offset.x;
+ }
}
if (p_cell.flip_v) {
xform.elements[0].y = -xform.elements[0].y;
xform.elements[1].y = -xform.elements[1].y;
- offset.y = s.y - offset.y;
+ if (compatibility_mode && !centered_textures) {
+ if (tile_origin == TILE_ORIGIN_TOP_LEFT) {
+ offset.y = s.y - offset.y;
+ } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
+ offset.y += s.y;
+ } else if (tile_origin == TILE_ORIGIN_CENTER) {
+ offset.y += s.y;
+ }
+ } else {
+ offset.y = s.y - offset.y;
+ }
+ }
+
+ if (centered_textures) {
+ offset += cell_size / 2 - s / 2;
}
- /* For a future CheckBox to Center Texture:
- offset += cell_size / 2 - s / 2; */
xform.elements[2] += offset;
}
+void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> &p_shape, const TileSet::ShapeData &p_shape_data, const Transform2D &p_xform, const Vector2 &p_metadata) {
+ Physics2DServer *ps = Physics2DServer::get_singleton();
+
+ if (!use_parent) {
+ ps->body_add_shape(p_q.body, p_shape->get_rid(), p_xform);
+ ps->body_set_shape_metadata(p_q.body, shape_idx, p_metadata);
+ ps->body_set_shape_as_one_way_collision(p_q.body, shape_idx, p_shape_data.one_way_collision, p_shape_data.one_way_collision_margin);
+
+ } else if (collision_parent) {
+ Transform2D xform = p_xform;
+ xform.set_origin(xform.get_origin() + p_q.pos);
+
+ collision_parent->shape_owner_add_shape(p_q.shape_owner_id, p_shape);
+
+ int real_index = collision_parent->shape_owner_get_shape_index(p_q.shape_owner_id, shape_idx);
+ RID rid = collision_parent->get_rid();
+
+ if (Object::cast_to<Area2D>(collision_parent) != NULL) {
+ ps->area_set_shape_transform(rid, real_index, get_transform() * xform);
+ } else {
+ ps->body_set_shape_transform(rid, real_index, get_transform() * xform);
+ ps->body_set_shape_metadata(rid, real_index, p_metadata);
+ ps->body_set_shape_as_one_way_collision(rid, real_index, p_shape_data.one_way_collision, p_shape_data.one_way_collision_margin);
+ }
+ }
+ shape_idx++;
+}
+
void TileMap::update_dirty_quadrants() {
if (!pending_update)
@@ -268,7 +367,11 @@ void TileMap::update_dirty_quadrants() {
q.canvas_items.clear();
- ps->body_clear_shapes(q.body);
+ if (!use_parent) {
+ ps->body_clear_shapes(q.body);
+ } else if (collision_parent) {
+ collision_parent->shape_owner_clear_shapes(q.shape_owner_id);
+ }
int shape_idx = 0;
if (navigation) {
@@ -370,13 +473,24 @@ void TileMap::update_dirty_quadrants() {
rect.size.x += fp_adjust;
rect.size.y += fp_adjust;
+ if (compatibility_mode && !centered_textures) {
+ if (rect.size.y > rect.size.x) {
+ if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose))
+ tile_ofs.y += rect.size.y - rect.size.x;
+ } else if (rect.size.y < rect.size.x) {
+ if ((c.flip_v && (c.flip_h || c.transpose)) || (c.flip_h && !c.transpose))
+ tile_ofs.x += rect.size.x - rect.size.y;
+ }
+ }
+
if (c.transpose) {
SWAP(tile_ofs.x, tile_ofs.y);
- /* For a future CheckBox to Center Texture:
- rect.position.x += cell_size.x / 2 - rect.size.y / 2;
- rect.position.y += cell_size.y / 2 - rect.size.x / 2;
- } else {
- rect.position += cell_size / 2 - rect.size / 2; */
+ if (centered_textures) {
+ rect.position.x += cell_size.x / 2 - rect.size.y / 2;
+ rect.position.y += cell_size.y / 2 - rect.size.x / 2;
+ }
+ } else if (centered_textures) {
+ rect.position += cell_size / 2 - rect.size / 2;
}
if (c.flip_h) {
@@ -389,7 +503,43 @@ void TileMap::update_dirty_quadrants() {
tile_ofs.y = -tile_ofs.y;
}
- rect.position += tile_ofs;
+ if (compatibility_mode && !centered_textures) {
+ if (tile_origin == TILE_ORIGIN_TOP_LEFT) {
+ rect.position += tile_ofs;
+
+ } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
+
+ rect.position += tile_ofs;
+
+ if (c.transpose) {
+ if (c.flip_h)
+ rect.position.x -= cell_size.x;
+ else
+ rect.position.x += cell_size.x;
+ } else {
+ if (c.flip_v)
+ rect.position.y -= cell_size.y;
+ else
+ rect.position.y += cell_size.y;
+ }
+
+ } else if (tile_origin == TILE_ORIGIN_CENTER) {
+
+ rect.position += tile_ofs;
+
+ if (c.flip_h)
+ rect.position.x -= cell_size.x / 2;
+ else
+ rect.position.x += cell_size.x / 2;
+
+ if (c.flip_v)
+ rect.position.y -= cell_size.y / 2;
+ else
+ rect.position.y += cell_size.y / 2;
+ }
+ } else {
+ rect.position += tile_ofs;
+ }
Ref<Texture> normal_map = tile_set->tile_get_normal_map(c.id);
Color modulate = tile_set->tile_get_modulate(c.id);
@@ -427,10 +577,7 @@ void TileMap::update_dirty_quadrants() {
for (int k = 0; k < _shapes.size(); k++) {
Ref<ConvexPolygonShape2D> convex = _shapes[k];
if (convex.is_valid()) {
- ps->body_add_shape(q.body, convex->get_rid(), xform);
- ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y));
- ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[j].one_way_collision, shapes[j].one_way_collision_margin);
- shape_idx++;
+ _add_shape(shape_idx, q, convex, shapes[j], xform, Vector2(E->key().x, E->key().y));
#ifdef DEBUG_ENABLED
} else {
print_error("The TileSet assigned to the TileMap " + get_name() + " has an invalid convex shape.");
@@ -438,10 +585,7 @@ void TileMap::update_dirty_quadrants() {
}
}
} else {
- ps->body_add_shape(q.body, shape->get_rid(), xform);
- ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y));
- ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[j].one_way_collision, shapes[j].one_way_collision_margin);
- shape_idx++;
+ _add_shape(shape_idx, q, shape, shapes[j], xform, Vector2(E->key().x, E->key().y));
}
}
}
@@ -616,22 +760,29 @@ 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();
- 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);
- Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, friction);
- Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, bounce);
-
- if (is_inside_tree()) {
- xform = get_global_transform() * xform;
- RID space = get_world_2d()->get_space();
- Physics2DServer::get_singleton()->body_set_space(q.body, space);
- }
+ if (!use_parent) {
+ 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_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform);
+ 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);
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, friction);
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, bounce);
+
+ if (is_inside_tree()) {
+ xform = get_global_transform() * xform;
+ RID space = get_world_2d()->get_space();
+ Physics2DServer::get_singleton()->body_set_space(q.body, space);
+ }
+
+ Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform);
+ } else if (collision_parent) {
+ xform = get_transform() * xform;
+ q.shape_owner_id = collision_parent->create_shape_owner(this);
+ } else {
+ q.shape_owner_id = -1;
+ }
rect_cache_dirty = true;
quadrant_order_dirty = true;
@@ -641,7 +792,12 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons
void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
Quadrant &q = Q->get();
- Physics2DServer::get_singleton()->free(q.body);
+ if (!use_parent) {
+ Physics2DServer::get_singleton()->free(q.body);
+ } else if (collision_parent) {
+ collision_parent->remove_shape_owner(q.shape_owner_id);
+ }
+
for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
VisualServer::get_singleton()->free(E->get());
@@ -1086,10 +1242,7 @@ void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
coord_x = decode_uint16(&local[8]);
coord_y = decode_uint16(&local[10]);
}
- /*
- if (x<-20 || y <-20 || x>4000 || y>4000)
- continue;
- */
+
set_cell(x, y, v, flip_h, flip_v, transpose, Vector2(coord_x, coord_y));
}
@@ -1135,20 +1288,24 @@ Rect2 TileMap::_edit_get_rect() const {
void TileMap::set_collision_layer(uint32_t p_layer) {
collision_layer = p_layer;
- for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
+ if (!use_parent) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q = E->get();
- Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer);
+ }
}
}
void TileMap::set_collision_mask(uint32_t p_mask) {
collision_mask = p_mask;
- for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
+ if (!use_parent) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q = E->get();
- Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask);
+ }
}
}
@@ -1184,13 +1341,40 @@ void TileMap::set_collision_use_kinematic(bool p_use_kinematic) {
_recreate_quadrants();
}
+bool TileMap::get_collision_use_parent() const {
+
+ return use_parent;
+}
+
+void TileMap::set_collision_use_parent(bool p_use_parent) {
+
+ if (use_parent == p_use_parent) return;
+
+ _clear_quadrants();
+
+ use_parent = p_use_parent;
+ set_notify_local_transform(use_parent);
+
+ if (use_parent && is_inside_tree()) {
+ collision_parent = Object::cast_to<CollisionObject2D>(get_parent());
+ } else {
+ collision_parent = NULL;
+ }
+
+ _recreate_quadrants();
+ _change_notify();
+ update_configuration_warning();
+}
+
void TileMap::set_collision_friction(float p_friction) {
friction = p_friction;
- for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
+ if (!use_parent) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q = E->get();
- Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, p_friction);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, p_friction);
+ }
}
}
@@ -1202,10 +1386,12 @@ float TileMap::get_collision_friction() const {
void TileMap::set_collision_bounce(float p_bounce) {
bounce = p_bounce;
- for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
+ if (!use_parent) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q = E->get();
- Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, p_bounce);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, p_bounce);
+ }
}
}
float TileMap::get_collision_bounce() const {
@@ -1404,6 +1590,12 @@ void TileMap::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(p);
}
+void TileMap::_validate_property(PropertyInfo &property) const {
+ if (use_parent && property.name != "collision_use_parent" && property.name.begins_with("collision_")) {
+ property.usage = PROPERTY_USAGE_NOEDITOR;
+ }
+}
+
Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const {
return _map_to_world(p_pos.x, p_pos.y, p_ignore_ofs);
@@ -1461,6 +1653,32 @@ bool TileMap::is_y_sort_mode_enabled() const {
return y_sort_mode;
}
+void TileMap::set_compatibility_mode(bool p_enable) {
+
+ _clear_quadrants();
+ compatibility_mode = p_enable;
+ _recreate_quadrants();
+ emit_signal("settings_changed");
+}
+
+bool TileMap::is_compatibility_mode_enabled() const {
+
+ return compatibility_mode;
+}
+
+void TileMap::set_centered_textures(bool p_enable) {
+
+ _clear_quadrants();
+ centered_textures = p_enable;
+ _recreate_quadrants();
+ emit_signal("settings_changed");
+}
+
+bool TileMap::is_centered_textures_enabled() const {
+
+ return centered_textures;
+}
+
Array TileMap::get_used_cells() const {
Array a;
@@ -1552,6 +1770,20 @@ bool TileMap::get_clip_uv() const {
return clip_uv;
}
+String TileMap::get_configuration_warning() const {
+
+ String warning = Node2D::get_configuration_warning();
+
+ if (use_parent && !collision_parent) {
+ if (!warning.empty()) {
+ warning += "\n";
+ }
+ return TTR("TileMap with Use Parent on needs a parent CollisionObject2D to give shapes to. Please use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape.");
+ }
+
+ return warning;
+}
+
void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset);
@@ -1584,9 +1816,18 @@ void TileMap::_bind_methods() {
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);
+ ClassDB::bind_method(D_METHOD("set_compatibility_mode", "enable"), &TileMap::set_compatibility_mode);
+ ClassDB::bind_method(D_METHOD("is_compatibility_mode_enabled"), &TileMap::is_compatibility_mode_enabled);
+
+ ClassDB::bind_method(D_METHOD("set_centered_textures", "enable"), &TileMap::set_centered_textures);
+ ClassDB::bind_method(D_METHOD("is_centered_textures_enabled"), &TileMap::is_centered_textures_enabled);
+
ClassDB::bind_method(D_METHOD("set_collision_use_kinematic", "use_kinematic"), &TileMap::set_collision_use_kinematic);
ClassDB::bind_method(D_METHOD("get_collision_use_kinematic"), &TileMap::get_collision_use_kinematic);
+ ClassDB::bind_method(D_METHOD("set_collision_use_parent", "use_parent"), &TileMap::set_collision_use_parent);
+ ClassDB::bind_method(D_METHOD("get_collision_use_parent"), &TileMap::get_collision_use_parent);
+
ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &TileMap::set_collision_layer);
ClassDB::bind_method(D_METHOD("get_collision_layer"), &TileMap::get_collision_layer);
@@ -1649,9 +1890,12 @@ void TileMap::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled,Offset Negative X,Offset Negative Y"), "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, "compatibility_mode"), "set_compatibility_mode", "is_compatibility_mode_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered_textures"), "set_centered_textures", "is_centered_textures_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_parent", PROPERTY_HINT_NONE, ""), "set_collision_use_parent", "get_collision_use_parent");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_kinematic", PROPERTY_HINT_NONE, ""), "set_collision_use_kinematic", "get_collision_use_kinematic");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision_friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_friction", "get_collision_friction");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision_bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_bounce", "get_collision_bounce");
@@ -1700,9 +1944,13 @@ TileMap::TileMap() {
bounce = 0;
mode = MODE_SQUARE;
half_offset = HALF_OFFSET_DISABLED;
+ use_parent = false;
+ collision_parent = NULL;
use_kinematic = false;
navigation = NULL;
y_sort_mode = false;
+ compatibility_mode = false;
+ centered_textures = false;
occluder_light_mask = 1;
clip_uv = false;
format = FORMAT_1; //Always initialize with the lowest format
@@ -1710,6 +1958,7 @@ TileMap::TileMap() {
fp_adjust = 0.00001;
tile_origin = TILE_ORIGIN_TOP_LEFT;
set_notify_transform(true);
+ set_notify_local_transform(false);
}
TileMap::~TileMap() {
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 6a1467aa48..6c9648ff32 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -37,6 +37,8 @@
#include "scene/2d/node_2d.h"
#include "scene/resources/tile_set.h"
+class CollisionObject2D;
+
class TileMap : public Node2D {
GDCLASS(TileMap, Node2D);
@@ -74,6 +76,8 @@ private:
Mode mode;
Transform2D custom_transform;
HalfOffset half_offset;
+ bool use_parent;
+ CollisionObject2D *collision_parent;
bool use_kinematic;
Navigation2D *navigation;
@@ -123,6 +127,7 @@ private:
Vector2 pos;
List<RID> canvas_items;
RID body;
+ uint32_t shape_owner_id;
SelfList<Quadrant> dirty_list;
@@ -145,6 +150,7 @@ private:
pos = q.pos;
canvas_items = q.canvas_items;
body = q.body;
+ shape_owner_id = q.shape_owner_id;
cells = q.cells;
navpoly_ids = q.navpoly_ids;
occluder_instances = q.occluder_instances;
@@ -154,6 +160,7 @@ private:
pos = q.pos;
canvas_items = q.canvas_items;
body = q.body;
+ shape_owner_id = q.shape_owner_id;
cells = q.cells;
occluder_instances = q.occluder_instances;
navpoly_ids = q.navpoly_ids;
@@ -174,6 +181,8 @@ private:
bool used_size_cache_dirty;
bool quadrant_order_dirty;
bool y_sort_mode;
+ bool compatibility_mode;
+ bool centered_textures;
bool clip_uv;
float fp_adjust;
float friction;
@@ -188,6 +197,8 @@ private:
void _fix_cell_transform(Transform2D &xform, const Cell &p_cell, const Vector2 &p_offset, const Size2 &p_sc);
+ void _add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> &p_shape, const TileSet::ShapeData &p_shape_data, const Transform2D &p_xform, const Vector2 &p_metadata);
+
Map<PosKey, Quadrant>::Element *_create_quadrant(const PosKey &p_qk);
void _erase_quadrant(Map<PosKey, Quadrant>::Element *Q);
void _make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update = true);
@@ -218,6 +229,7 @@ protected:
void _notification(int p_what);
static void _bind_methods();
+ virtual void _validate_property(PropertyInfo &property) const;
virtual void _changed_callback(Object *p_changed, const char *p_prop);
public:
@@ -271,6 +283,9 @@ public:
void set_collision_use_kinematic(bool p_use_kinematic);
bool get_collision_use_kinematic() const;
+ void set_collision_use_parent(bool p_use_parent);
+ bool get_collision_use_parent() const;
+
void set_collision_friction(float p_friction);
float get_collision_friction() const;
@@ -298,6 +313,12 @@ public:
void set_y_sort_mode(bool p_enable);
bool is_y_sort_mode_enabled() const;
+ void set_compatibility_mode(bool p_enable);
+ bool is_compatibility_mode_enabled() const;
+
+ void set_centered_textures(bool p_enable);
+ bool is_centered_textures_enabled() const;
+
Array get_used_cells() const;
Array get_used_cells_by_id(int p_id) const;
Rect2 get_used_rect(); // Not const because of cache
@@ -314,6 +335,8 @@ public:
void set_clip_uv(bool p_enable);
bool get_clip_uv() const;
+ String get_configuration_warning() const;
+
void fix_invalid_tiles();
void clear();