summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/SCsub2
-rw-r--r--scene/2d/animated_sprite.cpp24
-rw-r--r--scene/2d/area_2d.cpp70
-rw-r--r--scene/2d/area_2d.h10
-rw-r--r--scene/2d/back_buffer_copy.cpp4
-rw-r--r--scene/2d/back_buffer_copy.h2
-rw-r--r--scene/2d/camera_2d.cpp71
-rw-r--r--scene/2d/camera_2d.h14
-rw-r--r--scene/2d/canvas_item.cpp25
-rw-r--r--scene/2d/canvas_item.h7
-rw-r--r--scene/2d/collision_object_2d.cpp58
-rw-r--r--scene/2d/collision_polygon_2d.cpp100
-rw-r--r--scene/2d/collision_polygon_2d.h12
-rw-r--r--scene/2d/collision_shape_2d.cpp165
-rw-r--r--scene/2d/collision_shape_2d.h8
-rw-r--r--scene/2d/joints_2d.cpp28
-rw-r--r--scene/2d/joints_2d.h6
-rw-r--r--scene/2d/light_2d.cpp16
-rw-r--r--scene/2d/light_2d.h5
-rw-r--r--scene/2d/navigation2d.cpp35
-rw-r--r--scene/2d/navigation2d.h12
-rw-r--r--scene/2d/navigation_polygon.cpp10
-rw-r--r--scene/2d/node_2d.cpp24
-rw-r--r--scene/2d/node_2d.h3
-rw-r--r--scene/2d/parallax_background.cpp20
-rw-r--r--scene/2d/parallax_background.h4
-rw-r--r--scene/2d/particles_2d.cpp182
-rw-r--r--scene/2d/particles_2d.h15
-rw-r--r--scene/2d/path_2d.cpp2
-rw-r--r--scene/2d/physics_body_2d.cpp53
-rw-r--r--scene/2d/physics_body_2d.h12
-rw-r--r--scene/2d/ray_cast_2d.cpp27
-rw-r--r--scene/2d/ray_cast_2d.h4
-rw-r--r--scene/2d/sample_player_2d.cpp2
-rw-r--r--scene/2d/sprite.cpp52
-rw-r--r--scene/2d/tile_map.cpp30
-rw-r--r--scene/2d/tile_map.h2
-rw-r--r--scene/2d/visibility_notifier_2d.cpp22
-rw-r--r--scene/2d/visibility_notifier_2d.h2
39 files changed, 797 insertions, 343 deletions
diff --git a/scene/2d/SCsub b/scene/2d/SCsub
index 055d2f2474..bbe59b3054 100644
--- a/scene/2d/SCsub
+++ b/scene/2d/SCsub
@@ -3,5 +3,3 @@ Import('env')
env.add_source_files(env.scene_sources,"*.cpp")
Export('env')
-
-
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index 312b04d414..458246671c 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -28,6 +28,8 @@
/*************************************************************************/
#include "animated_sprite.h"
#include "scene/scene_string_names.h"
+#include "os/os.h"
+
void AnimatedSprite::edit_set_pivot(const Point2& p_pivot) {
set_offset(p_pivot);
@@ -149,18 +151,22 @@ void AnimatedSprite::_notification(int p_what) {
Size2i s;
s = texture->get_size();
- Point2i ofs=offset;
+ Point2 ofs=offset;
if (centered)
ofs-=s/2;
- Rect2i dst_rect(ofs,s);
+ if (OS::get_singleton()->get_use_pixel_snap()) {
+ ofs=ofs.floor();
+ }
+ Rect2 dst_rect(ofs,s);
if (hflip)
dst_rect.size.x=-dst_rect.size.x;
if (vflip)
dst_rect.size.y=-dst_rect.size.y;
- texture->draw_rect(ci,dst_rect,false,modulate);
+ //texture->draw_rect(ci,dst_rect,false,modulate);
+ texture->draw_rect_region(ci,dst_rect,Rect2(Vector2(),texture->get_size()),modulate);
// VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate);
} break;
@@ -284,7 +290,7 @@ Rect2 AnimatedSprite::get_item_rect() const {
return Node2D::get_item_rect();
Size2i s = t->get_size();
- Point2i ofs=offset;
+ Point2 ofs=offset;
if (centered)
ofs-=s/2;
@@ -329,12 +335,12 @@ void AnimatedSprite::_bind_methods() {
ADD_SIGNAL(MethodInfo("frame_changed"));
ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "frames",PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), _SCS("set_sprite_frames"),_SCS("get_sprite_frames"));
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered"));
ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_h"), _SCS("set_flip_h"),_SCS("is_flipped_h"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_v"), _SCS("set_flip_v"),_SCS("is_flipped_v"));
- ADD_PROPERTY( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_h"), _SCS("set_flip_h"),_SCS("is_flipped_h"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_v"), _SCS("set_flip_v"),_SCS("is_flipped_v"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate"));
}
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 827256c2fa..c44b46adbf 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -52,6 +52,17 @@ bool Area2D::is_gravity_a_point() const{
return gravity_is_point;
}
+void Area2D::set_gravity_distance_scale(real_t p_scale){
+
+ gravity_distance_scale=p_scale;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale);
+
+}
+
+real_t Area2D::get_gravity_distance_scale() const{
+ return gravity_distance_scale;
+}
+
void Area2D::set_gravity_vector(const Vector2& p_vec){
gravity_vec=p_vec;
@@ -417,8 +428,9 @@ void Area2D::set_enable_monitoring(bool p_enable) {
if (monitoring) {
- Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),this,"_body_inout");
- Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,"_area_inout");
+ Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_body_inout);
+ Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_area_inout);
+
} else {
Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName());
Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName());
@@ -535,6 +547,39 @@ uint32_t Area2D::get_layer_mask() const {
return layer_mask;
}
+void Area2D::set_collision_mask_bit(int p_bit, bool p_value) {
+
+ uint32_t mask = get_collision_mask();
+ if (p_value)
+ mask|=1<<p_bit;
+ else
+ mask&=~(1<<p_bit);
+ set_collision_mask(mask);
+
+}
+
+bool Area2D::get_collision_mask_bit(int p_bit) const{
+
+ return get_collision_mask()&(1<<p_bit);
+}
+
+
+void Area2D::set_layer_mask_bit(int p_bit, bool p_value) {
+
+ uint32_t mask = get_layer_mask();
+ if (p_value)
+ mask|=1<<p_bit;
+ else
+ mask&=~(1<<p_bit);
+ set_layer_mask(mask);
+
+}
+
+bool Area2D::get_layer_mask_bit(int p_bit) const{
+
+ return get_layer_mask()&(1<<p_bit);
+}
+
void Area2D::_bind_methods() {
@@ -550,6 +595,9 @@ void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_gravity_is_point","enable"),&Area2D::set_gravity_is_point);
ObjectTypeDB::bind_method(_MD("is_gravity_a_point"),&Area2D::is_gravity_a_point);
+ ObjectTypeDB::bind_method(_MD("set_gravity_distance_scale","distance_scale"),&Area2D::set_gravity_distance_scale);
+ ObjectTypeDB::bind_method(_MD("get_gravity_distance_scale"),&Area2D::get_gravity_distance_scale);
+
ObjectTypeDB::bind_method(_MD("set_gravity_vector","vector"),&Area2D::set_gravity_vector);
ObjectTypeDB::bind_method(_MD("get_gravity_vector"),&Area2D::get_gravity_vector);
@@ -571,6 +619,12 @@ void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_layer_mask","layer_mask"),&Area2D::set_layer_mask);
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&Area2D::get_layer_mask);
+ ObjectTypeDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&Area2D::set_collision_mask_bit);
+ ObjectTypeDB::bind_method(_MD("get_collision_mask_bit","bit"),&Area2D::get_collision_mask_bit);
+
+ ObjectTypeDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&Area2D::set_layer_mask_bit);
+ ObjectTypeDB::bind_method(_MD("get_layer_mask_bit","bit"),&Area2D::get_layer_mask_bit);
+
ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring);
ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled);
@@ -599,16 +653,17 @@ void Area2D::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point"));
+ ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point"));
+ ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_gravity_distance_scale"),_SCS("get_gravity_distance_scale"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_linear_damp"),_SCS("get_linear_damp"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_angular_damp"),_SCS("get_angular_damp"));
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_mask"),_SCS("get_collision_mask"));
+ ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled"));
+ ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable"));
+ ADD_PROPERTYNO( PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
+ ADD_PROPERTYNO( PropertyInfo(Variant::INT,"collision/mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_mask"),_SCS("get_collision_mask"));
}
@@ -618,6 +673,7 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea
set_gravity(98);;
set_gravity_vector(Vector2(0,1));
gravity_is_point=false;
+ gravity_distance_scale=0;
linear_damp=0.1;
angular_damp=1;
locked=false;
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index 0c064f54cd..f5a88390e7 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -49,6 +49,7 @@ private:
Vector2 gravity_vec;
real_t gravity;
bool gravity_is_point;
+ real_t gravity_distance_scale;
real_t linear_damp;
real_t angular_damp;
uint32_t collision_mask;
@@ -132,6 +133,9 @@ public:
void set_gravity_is_point(bool p_enabled);
bool is_gravity_a_point() const;
+ void set_gravity_distance_scale(real_t p_scale);
+ real_t get_gravity_distance_scale() const;
+
void set_gravity_vector(const Vector2& p_vec);
Vector2 get_gravity_vector() const;
@@ -159,6 +163,12 @@ public:
void set_layer_mask(uint32_t p_mask);
uint32_t get_layer_mask() const;
+ void set_collision_mask_bit(int p_bit, bool p_value);
+ bool get_collision_mask_bit(int p_bit) const;
+
+ void set_layer_mask_bit(int p_bit, bool p_value);
+ bool get_layer_mask_bit(int p_bit) const;
+
Array get_overlapping_bodies() const; //function for script
Array get_overlapping_areas() const; //function for script
diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp
index 245b3ba7eb..7a138830db 100644
--- a/scene/2d/back_buffer_copy.cpp
+++ b/scene/2d/back_buffer_copy.cpp
@@ -4,7 +4,7 @@ void BackBufferCopy::_update_copy_mode() {
switch(copy_mode) {
- case COPY_MODE_DISALED: {
+ case COPY_MODE_DISABLED: {
VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2());
} break;
@@ -58,7 +58,7 @@ void BackBufferCopy::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT,"copy_mode",PROPERTY_HINT_ENUM,"Disabled,Rect,Viewport"),_SCS("set_copy_mode"),_SCS("get_copy_mode"));
ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),_SCS("set_rect"),_SCS("get_rect"));
- BIND_CONSTANT( COPY_MODE_DISALED );
+ BIND_CONSTANT( COPY_MODE_DISABLED );
BIND_CONSTANT( COPY_MODE_RECT );
BIND_CONSTANT( COPY_MODE_VIEWPORT );
diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h
index 3a86ffa309..734cad458a 100644
--- a/scene/2d/back_buffer_copy.h
+++ b/scene/2d/back_buffer_copy.h
@@ -7,7 +7,7 @@ class BackBufferCopy : public Node2D {
OBJ_TYPE( BackBufferCopy,Node2D);
public:
enum CopyMode {
- COPY_MODE_DISALED,
+ COPY_MODE_DISABLED,
COPY_MODE_RECT,
COPY_MODE_VIEWPORT
};
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index 27a512845c..52ae5d2954 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -57,7 +57,9 @@ void Camera2D::_update_scroll() {
void Camera2D::set_zoom(const Vector2 &p_zoom) {
zoom = p_zoom;
+ Point2 old_smoothed_camera_pos = smoothed_camera_pos;
_update_scroll();
+ smoothed_camera_pos = old_smoothed_camera_pos;
};
Vector2 Camera2D::get_zoom() const {
@@ -81,43 +83,47 @@ Matrix32 Camera2D::get_camera_transform() {
if (!first) {
- if (centered) {
+ if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) {
- if (h_drag_enabled) {
- camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT]));
- camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT]));
- } else {
+ if (h_drag_enabled) {
+ camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT]));
+ camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT]));
+ } else {
- if (h_ofs<0) {
- camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
- } else {
- camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs;
- }
- }
+ if (h_ofs<0) {
+ camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
+ } else {
+ camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs;
+ }
+ }
+
+ if (v_drag_enabled) {
- if (v_drag_enabled) {
+ camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM]));
+ camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));
- camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM]));
- camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));
+ } else {
- } else {
+ if (v_ofs<0) {
+ camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
+ } else {
+ camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
+ }
+ }
- if (v_ofs<0) {
- camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
- } else {
- camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
- }
- }
+ } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){
+ camera_pos=new_camera_pos;
}
+
if (smoothing>0.0) {
float c = smoothing*get_fixed_process_delta_time();
smoothed_camera_pos = ((new_camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos;
ret_camera_pos=smoothed_camera_pos;
-// camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
+ // camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
} else {
ret_camera_pos=smoothed_camera_pos=camera_pos;
@@ -132,8 +138,7 @@ Matrix32 Camera2D::get_camera_transform() {
}
- Point2 screen_offset = (centered ? (screen_size * 0.5 * zoom) : Point2());;
- screen_offset;
+ Point2 screen_offset = (anchor_mode==ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
float angle = get_global_transform().get_rotation();
if(rotating){
@@ -268,15 +273,15 @@ Vector2 Camera2D::get_offset() const{
return offset;
}
-void Camera2D::set_centered(bool p_centered){
+void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode){
- centered=p_centered;
+ anchor_mode=p_anchor_mode;
_update_scroll();
}
-bool Camera2D::is_centered() const {
+Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
- return centered;
+ return anchor_mode;
}
void Camera2D::set_rotating(bool p_rotating){
@@ -440,8 +445,8 @@ void Camera2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_offset","offset"),&Camera2D::set_offset);
ObjectTypeDB::bind_method(_MD("get_offset"),&Camera2D::get_offset);
- ObjectTypeDB::bind_method(_MD("set_centered","centered"),&Camera2D::set_centered);
- ObjectTypeDB::bind_method(_MD("is_centered"),&Camera2D::is_centered);
+ ObjectTypeDB::bind_method(_MD("set_anchor_mode","anchor_mode"),&Camera2D::set_anchor_mode);
+ ObjectTypeDB::bind_method(_MD("get_anchor_mode"),&Camera2D::get_anchor_mode);
ObjectTypeDB::bind_method(_MD("set_rotating","rotating"),&Camera2D::set_rotating);
ObjectTypeDB::bind_method(_MD("is_rotating"),&Camera2D::is_rotating);
@@ -488,7 +493,7 @@ void Camera2D::_bind_methods() {
ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_offset"),_SCS("get_offset"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"centered"),_SCS("set_centered"),_SCS("is_centered"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"anchor_mode",PROPERTY_HINT_ENUM,"Fixed TopLeft,Drag Center"),_SCS("set_anchor_mode"),_SCS("get_anchor_mode"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"rotating"),_SCS("set_rotating"),_SCS("is_rotating"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"current"),_SCS("_set_current"),_SCS("is_current"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"smoothing"),_SCS("set_follow_smoothing"),_SCS("get_follow_smoothing") );
@@ -508,6 +513,8 @@ void Camera2D::_bind_methods() {
ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin/bottom",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_drag_margin"),_SCS("get_drag_margin"),MARGIN_BOTTOM);
+ BIND_CONSTANT( ANCHOR_MODE_DRAG_CENTER );
+ BIND_CONSTANT( ANCHOR_MODE_FIXED_TOP_LEFT );
}
@@ -515,7 +522,7 @@ Camera2D::Camera2D() {
- centered=true;
+ anchor_mode=ANCHOR_MODE_DRAG_CENTER;
rotating=false;
current=false;
limit[MARGIN_LEFT]=-10000000;
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h
index 8975a2584b..79d84f48d0 100644
--- a/scene/2d/camera_2d.h
+++ b/scene/2d/camera_2d.h
@@ -36,6 +36,12 @@
class Camera2D : public Node2D {
OBJ_TYPE( Camera2D, Node2D );
+public:
+
+ enum AnchorMode {
+ ANCHOR_MODE_FIXED_TOP_LEFT,
+ ANCHOR_MODE_DRAG_CENTER
+ };
protected:
Point2 camera_pos;
@@ -49,7 +55,7 @@ protected:
RID canvas;
Vector2 offset;
Vector2 zoom;
- bool centered;
+ AnchorMode anchor_mode;
bool rotating;
bool current;
float smoothing;
@@ -77,8 +83,8 @@ public:
void set_offset(const Vector2& p_offset);
Vector2 get_offset() const;
- void set_centered(bool p_centered);
- bool is_centered() const;
+ void set_anchor_mode(AnchorMode p_anchor_mode);
+ AnchorMode get_anchor_mode() const;
void set_rotating(bool p_rotating);
bool is_rotating() const;
@@ -120,4 +126,6 @@ public:
Camera2D();
};
+VARIANT_ENUM_CAST(Camera2D::AnchorMode);
+
#endif // CAMERA_2D_H
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 9b2cdf4ea2..357aaa225b 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -265,7 +265,7 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
CanvasItem *c=get_child(i)->cast_to<CanvasItem>();
- if (c && c->hidden!=p_visible) //should the toplevels stop propagation? i think so but..
+ if (c && !c->hidden) //should the toplevels stop propagation? i think so but..
c->_propagate_visibility_changed(p_visible);
}
@@ -288,6 +288,7 @@ void CanvasItem::show() {
if (is_visible()) {
_propagate_visibility_changed(true);
}
+ _change_notify("visibility/visible");
}
@@ -305,6 +306,7 @@ void CanvasItem::hide() {
if (propagate)
_propagate_visibility_changed(false);
+ _change_notify("visibility/visible");
}
@@ -1069,8 +1071,8 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("draw_rect","rect","color"),&CanvasItem::draw_rect);
ObjectTypeDB::bind_method(_MD("draw_circle","pos","radius","color"),&CanvasItem::draw_circle);
ObjectTypeDB::bind_method(_MD("draw_texture","texture:Texture","pos"),&CanvasItem::draw_texture);
- ObjectTypeDB::bind_method(_MD("draw_texture_rect","texture:Texture","rect","tile","modulate"),&CanvasItem::draw_texture_rect,DEFVAL(false),DEFVAL(Color(1,1,1)));
- ObjectTypeDB::bind_method(_MD("draw_texture_rect_region","texture:Texture","rect","src_rect","modulate"),&CanvasItem::draw_texture_rect_region,DEFVAL(Color(1,1,1)));
+ ObjectTypeDB::bind_method(_MD("draw_texture_rect","texture:Texture","rect","tile","modulate","transpose"),&CanvasItem::draw_texture_rect,DEFVAL(Color(1,1,1)),DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("draw_texture_rect_region","texture:Texture","rect","src_rect","modulate","transpose"),&CanvasItem::draw_texture_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false));
ObjectTypeDB::bind_method(_MD("draw_style_box","style_box:StyleBox","rect"),&CanvasItem::draw_style_box);
ObjectTypeDB::bind_method(_MD("draw_primitive","points","colors","uvs","texture:Texture","width"),&CanvasItem::draw_primitive,DEFVAL(Array()),DEFVAL(Ref<Texture>()),DEFVAL(1.0));
ObjectTypeDB::bind_method(_MD("draw_polygon","points","colors","uvs","texture:Texture"),&CanvasItem::draw_polygon,DEFVAL(Array()),DEFVAL(Ref<Texture>()));
@@ -1101,14 +1103,14 @@ void CanvasItem::_bind_methods() {
BIND_VMETHOD(MethodInfo("_draw"));
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_opacity"),_SCS("get_opacity") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::REAL,"visibility/self_opacity",PROPERTY_HINT_RANGE, "0,1,0.01"), _SCS("set_self_opacity"),_SCS("get_self_opacity") );
ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"visibility/behind_parent"), _SCS("set_draw_behind_parent"),_SCS("is_draw_behind_parent_enabled") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility
ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") );
- ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/light_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_light_mask"),_SCS("get_light_mask") );
+ ADD_PROPERTYNO( PropertyInfo(Variant::INT,"visibility/light_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_light_mask"),_SCS("get_light_mask") );
ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"material/material",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), _SCS("set_material"),_SCS("get_material") );
ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"material/use_parent"), _SCS("set_use_parent_material"),_SCS("get_use_parent_material") );
//exporting these two things doesn't really make much sense i think
@@ -1170,6 +1172,14 @@ Matrix32 CanvasItem::get_viewport_transform() const {
}
+void CanvasItem::set_notify_local_transform(bool p_enable) {
+ notify_local_transform=p_enable;
+}
+
+bool CanvasItem::is_local_transform_notification_enabled() const {
+ return notify_local_transform;
+}
+
CanvasItem::CanvasItem() : xform_change(this) {
@@ -1189,6 +1199,7 @@ CanvasItem::CanvasItem() : xform_change(this) {
canvas_layer=NULL;
use_parent_material=false;
global_invalid=true;
+ notify_local_transform=false;
light_mask=1;
C=NULL;
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 6d8308dbe4..4885256c64 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -126,6 +126,7 @@ private:
bool block_transform_notify;
bool behind;
bool use_parent_material;
+ bool notify_local_transform;
Ref<CanvasItemMaterial> material;
@@ -155,7 +156,7 @@ private:
protected:
- _FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); }
+ _FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify && notify_local_transform) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); }
void item_rect_changed();
@@ -263,6 +264,10 @@ public:
Vector2 get_global_mouse_pos() const;
Vector2 get_local_mouse_pos() const;
+ void set_notify_local_transform(bool p_enable);
+ bool is_local_transform_notification_enabled() const;
+
+
CanvasItem();
~CanvasItem();
};
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index f577b81598..8b8caf13d3 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -115,19 +115,16 @@ void CollisionObject2D::_update_shapes() {
bool CollisionObject2D::_set(const StringName& p_name, const Variant& p_value) {
String name=p_name;
- if (name=="shape_count") {
+ if (name.begins_with("shapes/")) {
- shapes.resize(p_value);
- _update_shapes();
- _change_notify();
-
- } else if (name.begins_with("shapes/")) {
-
- int idx=name.get_slice("/",1).to_int();
- String what=name.get_slice("/",2);
- if (what=="shape")
- set_shape(idx,RefPtr(p_value));
- else if (what=="transform")
+ int idx=name.get_slicec('/',1).to_int();
+ String what=name.get_slicec('/',2);
+ if (what=="shape") {
+ if (idx>=shapes.size())
+ add_shape(RefPtr(p_value));
+ else
+ set_shape(idx,RefPtr(p_value));
+ } else if (what=="transform")
set_shape_transform(idx,p_value);
else if (what=="trigger")
set_shape_as_trigger(idx,p_value);
@@ -143,12 +140,10 @@ bool CollisionObject2D::_get(const StringName& p_name,Variant &r_ret) const {
String name=p_name;
- if (name=="shape_count") {
- r_ret= shapes.size();
- } else if (name.begins_with("shapes/")) {
+ if (name.begins_with("shapes/")) {
- int idx=name.get_slice("/",1).to_int();
- String what=name.get_slice("/",2);
+ int idx=name.get_slicec('/',1).to_int();
+ String what=name.get_slicec('/',2);
if (what=="shape")
r_ret= get_shape(idx);
else if (what=="transform")
@@ -163,7 +158,7 @@ bool CollisionObject2D::_get(const StringName& p_name,Variant &r_ret) const {
void CollisionObject2D::_get_property_list( List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo(Variant::INT,"shape_count",PROPERTY_HINT_RANGE,"0,256,1",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
+ //p_list->push_back( PropertyInfo(Variant::INT,"shape_count",PROPERTY_HINT_RANGE,"0,256,1",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
for(int i=0;i<shapes.size();i++) {
String path="shapes/"+itos(i)+"/";
@@ -254,12 +249,19 @@ void CollisionObject2D::_bind_methods() {
void CollisionObject2D::add_shape(const Ref<Shape2D>& p_shape, const Matrix32& p_transform) {
+ ERR_FAIL_COND(p_shape.is_null());
+
ShapeData sdata;
sdata.shape=p_shape;
sdata.xform=p_transform;
sdata.trigger=false;
- shapes.push_back(sdata);
- _update_shapes();
+
+ if (area)
+ Physics2DServer::get_singleton()->area_add_shape(get_rid(),p_shape->get_rid(),p_transform);
+ else
+ Physics2DServer::get_singleton()->body_add_shape(get_rid(),p_shape->get_rid(),p_transform);
+
+ shapes.push_back(sdata);
}
int CollisionObject2D::get_shape_count() const {
@@ -270,8 +272,15 @@ int CollisionObject2D::get_shape_count() const {
void CollisionObject2D::set_shape(int p_shape_idx, const Ref<Shape2D>& p_shape) {
ERR_FAIL_INDEX(p_shape_idx,shapes.size());
+ ERR_FAIL_COND(p_shape.is_null());
+
shapes[p_shape_idx].shape=p_shape;
- _update_shapes();
+ if (area)
+ Physics2DServer::get_singleton()->area_set_shape(get_rid(),p_shape_idx,p_shape->get_rid());
+ else
+ Physics2DServer::get_singleton()->body_set_shape(get_rid(),p_shape_idx,p_shape->get_rid());
+
+// _update_shapes();
}
void CollisionObject2D::set_shape_transform(int p_shape_idx, const Matrix32& p_transform) {
@@ -279,7 +288,12 @@ void CollisionObject2D::set_shape_transform(int p_shape_idx, const Matrix32& p_t
ERR_FAIL_INDEX(p_shape_idx,shapes.size());
shapes[p_shape_idx].xform=p_transform;
- _update_shapes();
+ if (area)
+ Physics2DServer::get_singleton()->area_set_shape_transform(get_rid(),p_shape_idx,p_transform);
+ else
+ Physics2DServer::get_singleton()->body_set_shape_transform(get_rid(),p_shape_idx,p_transform);
+
+// _update_shapes();
}
Ref<Shape2D> CollisionObject2D::get_shape(int p_shape_idx) const {
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index ceea41d1c8..1479cb7881 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -33,7 +33,7 @@
void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
- if (unparenting)
+ if (unparenting || !can_update_body)
return;
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
@@ -49,6 +49,7 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
Vector< Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon);
+ shape_from=co->get_shape_count();
for(int i=0;i<decomp.size();i++) {
Ref<ConvexPolygonShape2D> convex = memnew( ConvexPolygonShape2D );
convex->set_points(decomp[i]);
@@ -57,6 +58,11 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
co->set_shape_as_trigger(co->get_shape_count()-1,true);
}
+ shape_to=co->get_shape_count()-1;
+ if (shape_to<shape_from) {
+ shape_from=-1;
+ shape_to=-1;
+ }
} else {
@@ -78,6 +84,9 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
if (trigger)
co->set_shape_as_trigger(co->get_shape_count()-1,true);
+ shape_from=co->get_shape_count()-1;
+ shape_to=co->get_shape_count()-1;
+
}
@@ -86,6 +95,8 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
void CollisionPolygon2D::_update_parent() {
+ if (!can_update_body)
+ return;
Node *parent = get_parent();
if (!parent)
return;
@@ -101,33 +112,55 @@ void CollisionPolygon2D::_notification(int p_what) {
switch(p_what) {
case NOTIFICATION_ENTER_TREE: {
unparenting=false;
+ can_update_body=get_tree()->is_editor_hint();
+ } break;
+ case NOTIFICATION_EXIT_TREE: {
+ can_update_body=false;
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (!is_inside_tree())
break;
- _update_parent();
+ if (can_update_body) {
+ _update_parent();
+ } else if (shape_from>=0 && shape_to>=0) {
+ CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
+ for(int i=shape_from;i<=shape_to;i++) {
+ co->set_shape_transform(i,get_transform());
+ }
+ }
+
} break;
case NOTIFICATION_DRAW: {
+
+ if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ break;
+ }
+
+
for(int i=0;i<polygon.size();i++) {
Vector2 p = polygon[i];
Vector2 n = polygon[(i+1)%polygon.size()];
- draw_line(p,n,Color(0,0.6,0.7,0.5),3);
+ draw_line(p,n,Color(0.9,0.2,0.0,0.8),3);
}
+//#define DEBUG_DECOMPOSE
+#if defined(TOOLS_ENABLED) && defined (DEBUG_DECOMPOSE)
Vector< Vector<Vector2> > decomp = Geometry::decompose_polygon(polygon);
-#define DEBUG_DECOMPOSE
-#ifdef DEBUG_DECOMPOSE
Color c(0.4,0.9,0.1);
for(int i=0;i<decomp.size();i++) {
c.set_hsv( Math::fmod(c.get_h() + 0.738,1),c.get_s(),c.get_v(),0.5);
draw_colored_polygon(decomp[i],c);
}
+#else
+ draw_colored_polygon(polygon,get_tree()->get_debug_collisions_color());
#endif
+
+
} break;
case NOTIFICATION_UNPARENTED: {
unparenting = true;
@@ -141,20 +174,22 @@ void CollisionPolygon2D::set_polygon(const Vector<Point2>& p_polygon) {
polygon=p_polygon;
- for(int i=0;i<polygon.size();i++) {
- if (i==0)
- aabb=Rect2(polygon[i],Size2());
- else
- aabb.expand_to(polygon[i]);
- }
- if (aabb==Rect2()) {
+ if (can_update_body) {
+ for(int i=0;i<polygon.size();i++) {
+ if (i==0)
+ aabb=Rect2(polygon[i],Size2());
+ else
+ aabb.expand_to(polygon[i]);
+ }
+ if (aabb==Rect2()) {
- aabb=Rect2(-10,-10,20,20);
- } else {
- aabb.pos-=aabb.size*0.3;
- aabb.size+=aabb.size*0.6;
+ aabb=Rect2(-10,-10,20,20);
+ } else {
+ aabb.pos-=aabb.size*0.3;
+ aabb.size+=aabb.size*0.6;
+ }
+ _update_parent();
}
- _update_parent();
update();
}
@@ -184,6 +219,13 @@ void CollisionPolygon2D::set_trigger(bool p_trigger) {
trigger=p_trigger;
_update_parent();
+ if (!can_update_body && is_inside_tree() && shape_from>=0 && shape_to>=0) {
+ CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
+ for(int i=shape_from;i<=shape_to;i++) {
+ co->set_shape_as_trigger(i,p_trigger);
+ }
+
+ }
}
bool CollisionPolygon2D::is_trigger() const{
@@ -192,6 +234,17 @@ bool CollisionPolygon2D::is_trigger() const{
}
+void CollisionPolygon2D::_set_shape_range(const Vector2& p_range) {
+
+ shape_from=p_range.x;
+ shape_to=p_range.y;
+}
+
+Vector2 CollisionPolygon2D::_get_shape_range() const {
+
+ return Vector2(shape_from,shape_to);
+}
+
void CollisionPolygon2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_add_to_collision_object"),&CollisionPolygon2D::_add_to_collision_object);
@@ -204,9 +257,17 @@ void CollisionPolygon2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_trigger"),&CollisionPolygon2D::set_trigger);
ObjectTypeDB::bind_method(_MD("is_trigger"),&CollisionPolygon2D::is_trigger);
+ ObjectTypeDB::bind_method(_MD("_set_shape_range","shape_range"),&CollisionPolygon2D::_set_shape_range);
+ ObjectTypeDB::bind_method(_MD("_get_shape_range"),&CollisionPolygon2D::_get_shape_range);
+
+ ObjectTypeDB::bind_method(_MD("get_collision_object_first_shape"),&CollisionPolygon2D::get_collision_object_first_shape);
+ ObjectTypeDB::bind_method(_MD("get_collision_object_last_shape"),&CollisionPolygon2D::get_collision_object_last_shape);
+
ADD_PROPERTY( PropertyInfo(Variant::INT,"build_mode",PROPERTY_HINT_ENUM,"Solids,Segments"),_SCS("set_build_mode"),_SCS("get_build_mode"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2_ARRAY,"polygon"),_SCS("set_polygon"),_SCS("get_polygon"));
+ ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"shape_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_shape_range"),_SCS("_get_shape_range"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"trigger"),_SCS("set_trigger"),_SCS("is_trigger"));
+
}
CollisionPolygon2D::CollisionPolygon2D() {
@@ -215,6 +276,9 @@ CollisionPolygon2D::CollisionPolygon2D() {
build_mode=BUILD_SOLIDS;
trigger=false;
unparenting=false;
-
+ shape_from=-1;
+ shape_to=-1;
+ can_update_body=false;
+ set_notify_local_transform(true);
}
diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h
index 4e78868082..4bc9713c8a 100644
--- a/scene/2d/collision_polygon_2d.h
+++ b/scene/2d/collision_polygon_2d.h
@@ -56,6 +56,14 @@ protected:
void _add_to_collision_object(Object *p_obj);
void _update_parent();
+ bool can_update_body;
+ int shape_from;
+ int shape_to;
+
+ void _set_shape_range(const Vector2& p_range);
+ Vector2 _get_shape_range() const;
+
+
protected:
void _notification(int p_what);
@@ -72,6 +80,10 @@ public:
Vector<Point2> get_polygon() const;
virtual Rect2 get_item_rect() const;
+
+ int get_collision_object_first_shape() const { return shape_from; }
+ int get_collision_object_last_shape() const { return shape_to; }
+
CollisionPolygon2D();
};
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index 5012c54b17..85751fc735 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -44,10 +44,12 @@ void CollisionShape2D::_add_to_collision_object(Object *p_obj) {
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
+ update_shape_index=co->get_shape_count();
co->add_shape(shape,get_transform());
if (trigger)
co->set_shape_as_trigger(co->get_shape_count()-1,true);
+
}
void CollisionShape2D::_shape_changed() {
@@ -74,12 +76,27 @@ void CollisionShape2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
unparenting=false;
+ can_update_body=get_tree()->is_editor_hint();
+
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (!is_inside_tree())
break;
- _update_parent();
+ if (can_update_body) {
+ _update_parent();
+ } else if (update_shape_index>=0){
+
+ CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
+ if (co) {
+ co->set_shape_transform(update_shape_index,get_transform());
+ }
+
+ }
+
+ } break;
+ case NOTIFICATION_EXIT_TREE: {
+ can_update_body=false;
} break;
/*
@@ -92,106 +109,22 @@ void CollisionShape2D::_notification(int p_what) {
} break;*/
case NOTIFICATION_DRAW: {
- rect=Rect2();
-
- Color draw_col=Color(0,0.6,0.7,0.5);
-
- if (shape->cast_to<LineShape2D>()) {
-
- LineShape2D *l = shape->cast_to<LineShape2D>();
- Vector2 point = l->get_d() * l->get_normal();
-
- Vector2 l1[2]={point-l->get_normal().tangent()*100,point+l->get_normal().tangent()*100};
- draw_line(l1[0],l1[1],draw_col,3);
- Vector2 l2[2]={point,point+l->get_normal()*30};
- draw_line(l2[0],l2[1],draw_col,3);
- rect.pos=l1[0];
- rect.expand_to(l1[1]);
- rect.expand_to(l2[0]);
- rect.expand_to(l2[1]);
-
- } else if (shape->cast_to<SegmentShape2D>()) {
-
- SegmentShape2D *s = shape->cast_to<SegmentShape2D>();
- draw_line(s->get_a(),s->get_b(),draw_col,3);
- rect.pos=s->get_a();
- rect.expand_to(s->get_b());
-
- } else if (shape->cast_to<RayShape2D>()) {
-
- RayShape2D *s = shape->cast_to<RayShape2D>();
-
- Vector2 tip = Vector2(0,s->get_length());
- draw_line(Vector2(),tip,draw_col,3);
- Vector<Vector2> pts;
- float tsize=4;
- pts.push_back(tip+Vector2(0,tsize));
- pts.push_back(tip+Vector2(0.707*tsize,0));
- pts.push_back(tip+Vector2(-0.707*tsize,0));
- Vector<Color> cols;
- for(int i=0;i<3;i++)
- cols.push_back(draw_col);
-
- draw_primitive(pts,cols,Vector<Vector2>()); //small arrow
-
- rect.pos=Vector2();
- rect.expand_to(tip);
- rect=rect.grow(0.707*tsize);
-
- } else if (shape->cast_to<CircleShape2D>()) {
-
- CircleShape2D *s = shape->cast_to<CircleShape2D>();
- Vector<Vector2> points;
- for(int i=0;i<24;i++) {
-
- points.push_back(Vector2(Math::cos(i*Math_PI*2/24.0),Math::sin(i*Math_PI*2/24.0))*s->get_radius());
- }
-
- draw_colored_polygon(points,draw_col);
- rect.pos=-Point2(s->get_radius(),s->get_radius());
- rect.size=Point2(s->get_radius(),s->get_radius())*2.0;
-
- } else if (shape->cast_to<RectangleShape2D>()) {
-
- RectangleShape2D *s = shape->cast_to<RectangleShape2D>();
- Vector2 he = s->get_extents();
- rect=Rect2(-he,he*2.0);
- draw_rect(rect,draw_col);;
-
- } else if (shape->cast_to<CapsuleShape2D>()) {
-
- CapsuleShape2D *s = shape->cast_to<CapsuleShape2D>();
-
- Vector<Vector2> points;
- for(int i=0;i<24;i++) {
- Vector2 ofs = Vector2(0,(i>6 && i<=18) ? -s->get_height()*0.5 : s->get_height()*0.5);
-
- points.push_back(Vector2(Math::sin(i*Math_PI*2/24.0),Math::cos(i*Math_PI*2/24.0))*s->get_radius() + ofs);
- if (i==6 || i==18)
- points.push_back(Vector2(Math::sin(i*Math_PI*2/24.0),Math::cos(i*Math_PI*2/24.0))*s->get_radius() - ofs);
- }
-
- draw_colored_polygon(points,draw_col);
- Vector2 he=Point2(s->get_radius(),s->get_radius()+s->get_height()*0.5);
- rect.pos=-he;
- rect.size=he*2.0;
+ if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
+ break;
+ }
- } else if (shape->cast_to<ConvexPolygonShape2D>()) {
+ if (!shape.is_valid()) {
+ break;
+ }
- ConvexPolygonShape2D *s = shape->cast_to<ConvexPolygonShape2D>();
+ rect=Rect2();
- Vector<Vector2> points = s->get_points();
- for(int i=0;i<points.size();i++) {
- if (i==0)
- rect.pos=points[i];
- else
- rect.expand_to(points[i]);
- }
- draw_colored_polygon(points,draw_col);
+ Color draw_col=get_tree()->get_debug_collisions_color();
+ shape->draw(get_canvas_item(),draw_col);
- }
+ rect=shape->get_rect();
rect=rect.grow(3);
} break;
@@ -209,7 +142,14 @@ void CollisionShape2D::set_shape(const Ref<Shape2D>& p_shape) {
shape->disconnect("changed",this,"_shape_changed");
shape=p_shape;
update();
- _update_parent();
+ if (is_inside_tree() && can_update_body)
+ _update_parent();
+ if (is_inside_tree() && !can_update_body && update_shape_index>=0) {
+ CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
+ if (co) {
+ co->set_shape(update_shape_index,p_shape);
+ }
+ }
if (shape.is_valid())
shape->connect("changed",this,"_shape_changed");
@@ -228,7 +168,14 @@ Rect2 CollisionShape2D::get_item_rect() const {
void CollisionShape2D::set_trigger(bool p_trigger) {
trigger=p_trigger;
- _update_parent();
+ if (can_update_body) {
+ _update_parent();
+ } else if (is_inside_tree() && update_shape_index>=0){
+ CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
+ if (co) {
+ co->set_shape_as_trigger(update_shape_index,p_trigger);
+ }
+ }
}
bool CollisionShape2D::is_trigger() const{
@@ -236,6 +183,19 @@ bool CollisionShape2D::is_trigger() const{
return trigger;
}
+
+void CollisionShape2D::_set_update_shape_index(int p_index) {
+
+
+ update_shape_index=p_index;
+}
+
+int CollisionShape2D::_get_update_shape_index() const{
+
+ return update_shape_index;
+}
+
+
void CollisionShape2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_shape","shape"),&CollisionShape2D::set_shape);
@@ -245,14 +205,23 @@ void CollisionShape2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_trigger","enable"),&CollisionShape2D::set_trigger);
ObjectTypeDB::bind_method(_MD("is_trigger"),&CollisionShape2D::is_trigger);
+ ObjectTypeDB::bind_method(_MD("_set_update_shape_index","index"),&CollisionShape2D::_set_update_shape_index);
+ ObjectTypeDB::bind_method(_MD("_get_update_shape_index"),&CollisionShape2D::_get_update_shape_index);
+
+ ObjectTypeDB::bind_method(_MD("get_collision_object_shape_index"),&CollisionShape2D::get_collision_object_shape_index);
+
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D"),_SCS("set_shape"),_SCS("get_shape"));
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"trigger"),_SCS("set_trigger"),_SCS("is_trigger"));
+ ADD_PROPERTY( PropertyInfo( Variant::INT, "_update_shape_index", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_NOEDITOR), _SCS("_set_update_shape_index"), _SCS("_get_update_shape_index"));
+
}
CollisionShape2D::CollisionShape2D() {
rect=Rect2(-Point2(10,10),Point2(20,20));
-
+ set_notify_local_transform(true);
trigger=false;
unparenting = false;
+ can_update_body = false;
+ update_shape_index=-1;
}
diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h
index 507912d31e..82e1137174 100644
--- a/scene/2d/collision_shape_2d.h
+++ b/scene/2d/collision_shape_2d.h
@@ -39,7 +39,13 @@ class CollisionShape2D : public Node2D {
Rect2 rect;
bool trigger;
bool unparenting;
+ bool can_update_body;
void _shape_changed();
+ int update_shape_index;
+
+ void _set_update_shape_index(int p_index);
+ int _get_update_shape_index() const;
+
protected:
void _update_parent();
@@ -55,6 +61,8 @@ public:
void set_trigger(bool p_trigger);
bool is_trigger() const;
+ int get_collision_object_shape_index() const { return _get_update_shape_index(); }
+
CollisionShape2D();
};
diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp
index c1e91c2ecd..1df936535f 100644
--- a/scene/2d/joints_2d.cpp
+++ b/scene/2d/joints_2d.cpp
@@ -126,7 +126,7 @@ void Joint2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_a"), _SCS("set_node_a"),_SCS("get_node_a") );
ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_b"), _SCS("set_node_b"),_SCS("get_node_b") );
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias/bias",PROPERTY_HINT_RANGE,"0,0.9,0.01"), _SCS("set_bias"),_SCS("get_bias") );
+ ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias/bias",PROPERTY_HINT_RANGE,"0,0.9,0.001"), _SCS("set_bias"),_SCS("get_bias") );
}
@@ -175,15 +175,37 @@ RID PinJoint2D::_configure_joint() {
//add a collision exception between both
Physics2DServer::get_singleton()->body_add_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;
- return Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(),body_a->get_rid(),body_b?body_b->get_rid():RID());
+}
+
+void PinJoint2D::set_softness(real_t p_softness) {
+
+ softness=p_softness;
+ update();
+ if (get_joint().is_valid())
+ Physics2DServer::get_singleton()->pin_joint_set_param(get_joint(), Physics2DServer::PIN_JOINT_SOFTNESS, p_softness);
}
+real_t PinJoint2D::get_softness() const {
-PinJoint2D::PinJoint2D() {
+ return softness;
+}
+
+void PinJoint2D::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_softness","softness"), &PinJoint2D::set_softness);
+ ObjectTypeDB::bind_method(_MD("get_softness"), &PinJoint2D::get_softness);
+ ADD_PROPERTY( PropertyInfo( Variant::REAL, "softness", PROPERTY_HINT_EXP_RANGE,"0.00,16,0.01"), _SCS("set_softness"), _SCS("get_softness"));
+}
+
+PinJoint2D::PinJoint2D() {
+ softness = 0;
}
diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h
index ac72c6ce59..908e3a158e 100644
--- a/scene/2d/joints_2d.h
+++ b/scene/2d/joints_2d.h
@@ -72,13 +72,17 @@ class PinJoint2D : public Joint2D {
OBJ_TYPE(PinJoint2D,Joint2D);
+ real_t softness;
+
protected:
void _notification(int p_what);
virtual RID _configure_joint();
+ static void _bind_methods();
public:
-
+ void set_softness(real_t p_stiffness);
+ real_t get_softness() const;
PinJoint2D();
};
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index c0ab544d42..852a6fb46b 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -237,6 +237,16 @@ float Light2D::get_shadow_esm_multiplier() const{
return shadow_esm_multiplier;
}
+void Light2D::set_shadow_color( const Color& p_shadow_color) {
+ shadow_color=p_shadow_color;
+ VS::get_singleton()->canvas_light_set_shadow_color(canvas_light,shadow_color);
+}
+
+Color Light2D::get_shadow_color() const {
+ return shadow_color;
+}
+
+
void Light2D::_notification(int p_what) {
@@ -313,6 +323,10 @@ void Light2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_shadow_esm_multiplier","multiplier"),&Light2D::set_shadow_esm_multiplier);
ObjectTypeDB::bind_method(_MD("get_shadow_esm_multiplier"),&Light2D::get_shadow_esm_multiplier);
+ ObjectTypeDB::bind_method(_MD("set_shadow_color","shadow_color"),&Light2D::set_shadow_color);
+ ObjectTypeDB::bind_method(_MD("get_shadow_color"),&Light2D::get_shadow_color);
+
+
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset"));
@@ -327,6 +341,7 @@ void Light2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT,"range/layer_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"range/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow/enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled"));
+ ADD_PROPERTY( PropertyInfo(Variant::COLOR,"shadow/color"),_SCS("set_shadow_color"),_SCS("get_shadow_color"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/buffer_size",PROPERTY_HINT_RANGE,"32,16384,1"),_SCS("set_shadow_buffer_size"),_SCS("get_shadow_buffer_size"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/esm_multiplier",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_esm_multiplier"),_SCS("get_shadow_esm_multiplier"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_mask"),_SCS("get_item_shadow_mask"));
@@ -356,6 +371,7 @@ Light2D::Light2D() {
shadow_buffer_size=2048;
shadow_esm_multiplier=80;
energy=1.0;
+ shadow_color=Color(0,0,0,0);
}
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index ef875aec2f..bf61868bac 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -18,6 +18,7 @@ private:
bool enabled;
bool shadow;
Color color;
+ Color shadow_color;
float height;
float _scale;
float energy;
@@ -95,6 +96,10 @@ public:
void set_shadow_esm_multiplier( float p_multiplier);
float get_shadow_esm_multiplier() const;
+ void set_shadow_color( const Color& p_shadow_color);
+ Color get_shadow_color() const;
+
+
virtual Rect2 get_item_rect() const;
Light2D();
diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp
index 5a02501816..b7d51730a0 100644
--- a/scene/2d/navigation2d.cpp
+++ b/scene/2d/navigation2d.cpp
@@ -8,8 +8,6 @@ void Navigation2D::_navpoly_link(int p_id) {
NavMesh &nm=navpoly_map[p_id];
ERR_FAIL_COND(nm.linked);
- print_line("LINK");
-
DVector<Vector2> vertices=nm.navpoly->get_vertices();
int len = vertices.size();
if (len==0)
@@ -48,7 +46,6 @@ void Navigation2D::_navpoly_link(int p_id) {
e.point=_get_point(ep);
p.edges[j]=e;
-
int idxn = indices[(j+1)%plen];
if (idxn<0 || idxn>=len) {
valid=false;
@@ -91,9 +88,13 @@ void Navigation2D::_navpoly_link(int p_id) {
} else {
if (C->get().B!=NULL) {
- print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
+ ConnectionPending pending;
+ pending.polygon=&p;
+ pending.edge=j;
+ p.edges[j].P=C->get().pending.push_back(pending);
+ continue;
+ //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
- ERR_CONTINUE(C->get().B!=NULL); //wut
C->get().B=&p;
C->get().B_edge=j;
@@ -117,7 +118,7 @@ void Navigation2D::_navpoly_unlink(int p_id) {
NavMesh &nm=navpoly_map[p_id];
ERR_FAIL_COND(!nm.linked);
- print_line("UNLINK");
+ //print_line("UNLINK");
for (List<Polygon>::Element *E=nm.polygons.front();E;E=E->next()) {
@@ -133,7 +134,12 @@ void Navigation2D::_navpoly_unlink(int p_id) {
EdgeKey ek(edges[i].point,edges[next].point);
Map<EdgeKey,Connection>::Element *C=connections.find(ek);
ERR_CONTINUE(!C);
- if (C->get().B) {
+
+ if (edges[i].P) {
+ C->get().pending.erase(edges[i].P);
+ edges[i].P=NULL;
+
+ } else if (C->get().B) {
//disconnect
C->get().B->edges[C->get().B_edge].C=NULL;
@@ -149,6 +155,20 @@ void Navigation2D::_navpoly_unlink(int p_id) {
C->get().B=NULL;
C->get().B_edge=-1;
+ if (C->get().pending.size()) {
+ //reconnect if something is pending
+ ConnectionPending cp = C->get().pending.front()->get();
+ C->get().pending.pop_front();
+
+ C->get().B=cp.polygon;
+ C->get().B_edge=cp.edge;
+ C->get().A->edges[C->get().A_edge].C=cp.polygon;
+ C->get().A->edges[C->get().A_edge].C_edge=cp.edge;
+ cp.polygon->edges[cp.edge].C=C->get().A;
+ cp.polygon->edges[cp.edge].C_edge=C->get().A_edge;
+ cp.polygon->edges[cp.edge].P=NULL;
+ }
+
} else {
connections.erase(C);
//erase
@@ -335,7 +355,6 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
if (!begin_poly || !end_poly) {
- //print_line("No Path Path");
return Vector<Vector2>(); //no path
}
diff --git a/scene/2d/navigation2d.h b/scene/2d/navigation2d.h
index 829b0f544b..231f1e8c63 100644
--- a/scene/2d/navigation2d.h
+++ b/scene/2d/navigation2d.h
@@ -41,7 +41,13 @@ class Navigation2D : public Node2D {
struct NavMesh;
+ struct Polygon;
+ struct ConnectionPending {
+
+ Polygon *polygon;
+ int edge;
+ };
struct Polygon {
@@ -49,7 +55,8 @@ class Navigation2D : public Node2D {
Point point;
Polygon *C; //connection
int C_edge;
- Edge() { C=NULL; C_edge=-1; }
+ List<ConnectionPending>::Element *P;
+ Edge() { C=NULL; C_edge=-1; P=NULL; }
};
Vector<Edge> edges;
@@ -72,6 +79,9 @@ class Navigation2D : public Node2D {
int A_edge;
Polygon *B;
int B_edge;
+
+ List<ConnectionPending> pending;
+
Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;}
};
diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp
index fc69ea8a0d..792f079ab0 100644
--- a/scene/2d/navigation_polygon.cpp
+++ b/scene/2d/navigation_polygon.cpp
@@ -279,7 +279,7 @@ void NavigationPolygonInstance::set_enabled(bool p_enabled) {
}
- if (get_tree()->is_editor_hint())
+ if (get_tree()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())
update();
// update_gizmo();
@@ -338,7 +338,7 @@ void NavigationPolygonInstance::_notification(int p_what) {
} break;
case NOTIFICATION_DRAW: {
- if (is_inside_tree() && get_tree()->is_editor_hint() && navpoly.is_valid()) {
+ if (is_inside_tree() && (get_tree()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) {
DVector<Vector2> verts=navpoly->get_vertices();
int vsize = verts.size();
@@ -348,9 +348,9 @@ void NavigationPolygonInstance::_notification(int p_what) {
Color color;
if (enabled) {
- color=Color(0.1,0.8,1.0,0.4);
+ color=get_tree()->get_debug_navigation_color();
} else {
- color=Color(1.0,0.8,0.1,0.4);
+ color=get_tree()->get_debug_navigation_disabled_color();
}
Vector<Color> colors;
Vector<Vector2> vertices;
@@ -423,7 +423,7 @@ Ref<NavigationPolygon> NavigationPolygonInstance::get_navigation_polygon() const
void NavigationPolygonInstance::_navpoly_changed() {
- if (is_inside_tree() && get_tree()->is_editor_hint())
+ if (is_inside_tree() && (get_tree()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()))
update();
}
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index fc5be255ce..52b112f090 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -346,6 +346,17 @@ Matrix32 Node2D::get_relative_transform(const Node *p_parent) const {
return parent_2d->get_relative_transform(p_parent) * get_transform();
}
+
+void Node2D::look_at(const Vector2& p_pos) {
+
+ rotate(get_angle_to(p_pos));
+}
+
+float Node2D::get_angle_to(const Vector2& p_pos) const {
+
+ return (get_global_transform().affine_inverse().xform(p_pos)).angle();
+}
+
void Node2D::_bind_methods() {
@@ -374,6 +385,9 @@ void Node2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_transform","xform"),&Node2D::set_transform);
ObjectTypeDB::bind_method(_MD("set_global_transform","xform"),&Node2D::set_global_transform);
+ ObjectTypeDB::bind_method(_MD("look_at","point"),&Node2D::look_at);
+ ObjectTypeDB::bind_method(_MD("get_angle_to","point"),&Node2D::get_angle_to);
+
ObjectTypeDB::bind_method(_MD("set_z","z"),&Node2D::set_z);
ObjectTypeDB::bind_method(_MD("get_z"),&Node2D::get_z);
@@ -384,11 +398,11 @@ void Node2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_relative_transform"),&Node2D::get_relative_transform);
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/pos"),_SCS("set_pos"),_SCS("get_pos"));
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"transform/rot",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),_SCS("_set_rotd"),_SCS("_get_rotd"));
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"transform/scale"),_SCS("set_scale"),_SCS("get_scale"));
- ADD_PROPERTY(PropertyInfo(Variant::INT,"z/z",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z"),_SCS("get_z"));
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"z/relative"),_SCS("set_z_as_relative"),_SCS("is_z_relative"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"transform/pos"),_SCS("set_pos"),_SCS("get_pos"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"transform/rot",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),_SCS("_set_rotd"),_SCS("_get_rotd"));
+ ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"transform/scale"),_SCS("set_scale"),_SCS("get_scale"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT,"z/z",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z"),_SCS("get_z"));
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"z/relative"),_SCS("set_z_as_relative"),_SCS("is_z_relative"));
}
diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h
index 74612b3c6d..8efce33cda 100644
--- a/scene/2d/node_2d.h
+++ b/scene/2d/node_2d.h
@@ -93,6 +93,9 @@ public:
void set_z(int p_z);
int get_z() const;
+ void look_at(const Vector2& p_pos);
+ float get_angle_to(const Vector2& p_pos) const;
+
void set_z_as_relative(bool p_enabled);
bool is_z_relative() const;
diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp
index 109546bde3..8bb4eb55ba 100644
--- a/scene/2d/parallax_background.cpp
+++ b/scene/2d/parallax_background.cpp
@@ -110,7 +110,10 @@ void ParallaxBackground::_update_scroll() {
if (!l)
continue;
- l->set_base_offset_and_scale(ofs,scale);
+ if (ignore_camera_zoom)
+ l->set_base_offset_and_scale(ofs, 1.0);
+ else
+ l->set_base_offset_and_scale(ofs, scale);
}
}
@@ -165,6 +168,18 @@ Point2 ParallaxBackground::get_limit_end() const {
return limit_end;
}
+void ParallaxBackground::set_ignore_camera_zoom(bool ignore){
+
+ ignore_camera_zoom = ignore;
+
+}
+
+bool ParallaxBackground::is_ignore_camera_zoom(){
+
+ return ignore_camera_zoom;
+
+}
+
void ParallaxBackground::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_camera_moved"),&ParallaxBackground::_camera_moved);
@@ -178,6 +193,8 @@ void ParallaxBackground::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_limit_begin"),&ParallaxBackground::get_limit_begin);
ObjectTypeDB::bind_method(_MD("set_limit_end","ofs"),&ParallaxBackground::set_limit_end);
ObjectTypeDB::bind_method(_MD("get_limit_end"),&ParallaxBackground::get_limit_end);
+ ObjectTypeDB::bind_method(_MD("set_ignore_camera_zoom"), &ParallaxBackground::set_ignore_camera_zoom);
+ ObjectTypeDB::bind_method(_MD("is_ignore_camera_zoom"), &ParallaxBackground::is_ignore_camera_zoom);
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll/offset"),_SCS("set_scroll_offset"),_SCS("get_scroll_offset"));
@@ -185,6 +202,7 @@ void ParallaxBackground::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll/base_scale"),_SCS("set_scroll_base_scale"),_SCS("get_scroll_base_scale"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll/limit_begin"),_SCS("set_limit_begin"),_SCS("get_limit_begin"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll/limit_end"),_SCS("set_limit_end"),_SCS("get_limit_end"));
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL, "scroll/ignore_camera_zoom"), _SCS("set_ignore_camera_zoom"), _SCS("is_ignore_camera_zoom"));
}
diff --git a/scene/2d/parallax_background.h b/scene/2d/parallax_background.h
index 363236b2ad..8dede07a16 100644
--- a/scene/2d/parallax_background.h
+++ b/scene/2d/parallax_background.h
@@ -44,6 +44,7 @@ class ParallaxBackground : public CanvasLayer {
String group_name;
Point2 limit_begin;
Point2 limit_end;
+ bool ignore_camera_zoom;
void _update_scroll();
protected:
@@ -72,6 +73,9 @@ public:
void set_limit_end(const Point2& p_ofs);
Point2 get_limit_end() const;
+ void set_ignore_camera_zoom(bool ignore);
+ bool is_ignore_camera_zoom();
+
ParallaxBackground();
};
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 39d747c436..8f805ceba2 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -503,19 +503,6 @@ void Particles2D::_notification(int p_what) {
if (!local_space)
invxform=get_global_transform().affine_inverse();
- int col_count=0;
- float last=-1;
- ColorPhase cphase[MAX_COLOR_PHASES];
-
- for(int i=0;i<color_phase_count;i++) {
-
- if (color_phases[i].pos<=last)
- break;
- cphase[i]=color_phases[i];
- col_count++;
- }
-
-
int start_particle = (int)(time * (float)particle_count / lifetime);
for (int id=0;id<particle_count;++id) {
@@ -537,32 +524,14 @@ void Particles2D::_notification(int p_what) {
uint32_t rand_seed=p.seed*(i+1);
-
- int cpos=0;
-
- while(cpos<col_count) {
-
- if (cphase[cpos].pos > ptime)
- break;
- cpos++;
- }
-
- cpos--;
-
Color color;
- //could be faster..
- if (cpos==-1)
- color=Color(1,1,1,1);
- else {
- if (cpos==col_count-1)
- color=cphase[cpos].color;
- else {
- float diff = (cphase[cpos+1].pos-cphase[cpos].pos);
- if (diff>0)
- color=cphase[cpos].color.linear_interpolate(cphase[cpos+1].color, (ptime - cphase[cpos].pos) / diff );
- else
- color=cphase[cpos+1].color;
- }
+
+ if(color_ramp.is_valid())
+ {
+ color = color_ramp->get_color_at_offset(ptime);
+ } else
+ {
+ color = default_color;
}
@@ -813,6 +782,27 @@ Ref<Texture> Particles2D::get_texture() const {
return texture;
}
+void Particles2D::set_color(const Color& p_color) {
+
+ default_color = p_color;
+}
+
+Color Particles2D::get_color() const {
+
+ return default_color;
+}
+
+
+void Particles2D::set_color_ramp(const Ref<ColorRamp>& p_color_ramp) {
+
+ color_ramp=p_color_ramp;
+}
+
+Ref<ColorRamp> Particles2D::get_color_ramp() const {
+
+ return color_ramp;
+}
+
void Particles2D::set_emissor_offset(const Point2& p_offset) {
emissor_offset=p_offset;
@@ -834,40 +824,76 @@ bool Particles2D::is_using_local_space() const {
return local_space;
}
-
+//Deprecated. Converts color phases to color ramp
void Particles2D::set_color_phases(int p_phases) {
- ERR_FAIL_INDEX(p_phases,MAX_COLOR_PHASES+1);
- color_phase_count=p_phases;
+ //Create color ramp if we have 2 or more phases.
+ //Otherwise first phase phase will be assigned to default color.
+ if(p_phases > 1 && color_ramp.is_null())
+ {
+ color_ramp = Ref<ColorRamp>(memnew (ColorRamp()));
+ }
+ if(color_ramp.is_valid())
+ {
+ color_ramp->get_points().resize(p_phases);
+ }
}
+//Deprecated.
int Particles2D::get_color_phases() const {
- return color_phase_count;
+ if(color_ramp.is_valid())
+ {
+ return color_ramp->get_points_count();
+ }
+ return 0;
}
+//Deprecated. Converts color phases to color ramp
void Particles2D::set_color_phase_color(int p_phase,const Color& p_color) {
ERR_FAIL_INDEX(p_phase,MAX_COLOR_PHASES);
- color_phases[p_phase].color=p_color;
-
+ if(color_ramp.is_valid())
+ {
+ if(color_ramp->get_points_count() > p_phase)
+ color_ramp->set_color(p_phase, p_color);
+ } else
+ {
+ if(p_phase == 0)
+ default_color = p_color;
+ }
}
+
+//Deprecated.
Color Particles2D::get_color_phase_color(int p_phase) const {
ERR_FAIL_INDEX_V(p_phase,MAX_COLOR_PHASES,Color());
- return color_phases[p_phase].color;
+ if(color_ramp.is_valid())
+ {
+ return color_ramp->get_color(p_phase);
+ }
+ return Color(0,0,0,1);
}
+//Deprecated. Converts color phases to color ramp
void Particles2D::set_color_phase_pos(int p_phase,float p_pos) {
ERR_FAIL_INDEX(p_phase,MAX_COLOR_PHASES);
ERR_FAIL_COND(p_pos<0.0 || p_pos>1.0);
- color_phases[p_phase].pos=p_pos;
-
+ if(color_ramp.is_valid() && color_ramp->get_points_count() > p_phase)
+ {
+ return color_ramp->set_offset(p_phase, p_pos);
+ }
}
+
+//Deprecated.
float Particles2D::get_color_phase_pos(int p_phase) const {
ERR_FAIL_INDEX_V(p_phase,MAX_COLOR_PHASES,0);
- return color_phases[p_phase].pos;
+ if(color_ramp.is_valid())
+ {
+ return color_ramp->get_offset(p_phase);
+ }
+ return 0;
}
void Particles2D::set_emission_half_extents(const Vector2& p_extents) {
@@ -997,6 +1023,12 @@ void Particles2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_texture:Texture","texture"),&Particles2D::set_texture);
ObjectTypeDB::bind_method(_MD("get_texture:Texture"),&Particles2D::get_texture);
+ ObjectTypeDB::bind_method(_MD("set_color","color"),&Particles2D::set_color);
+ ObjectTypeDB::bind_method(_MD("get_color"),&Particles2D::get_color);
+
+ ObjectTypeDB::bind_method(_MD("set_color_ramp:ColorRamp","color_ramp"),&Particles2D::set_color_ramp);
+ ObjectTypeDB::bind_method(_MD("get_color_ramp:ColorRamp"),&Particles2D::get_color_ramp);
+
ObjectTypeDB::bind_method(_MD("set_emissor_offset","offset"),&Particles2D::set_emissor_offset);
ObjectTypeDB::bind_method(_MD("get_emissor_offset"),&Particles2D::get_emissor_offset);
@@ -1040,20 +1072,19 @@ void Particles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT,"config/amount",PROPERTY_HINT_EXP_RANGE,"1,1024"),_SCS("set_amount"),_SCS("get_amount") );
ADD_PROPERTY(PropertyInfo(Variant::REAL,"config/lifetime",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),_SCS("set_lifetime"),_SCS("get_lifetime") );
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"config/time_scale",PROPERTY_HINT_EXP_RANGE,"0.01,128,0.01"),_SCS("set_time_scale"),_SCS("get_time_scale") );
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"config/preprocess",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),_SCS("set_pre_process_time"),_SCS("get_pre_process_time") );
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"config/emit_timeout",PROPERTY_HINT_RANGE,"0,3600,0.1"),_SCS("set_emit_timeout"),_SCS("get_emit_timeout") );
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"config/emitting"),_SCS("set_emitting"),_SCS("is_emitting") );
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"config/offset"),_SCS("set_emissor_offset"),_SCS("get_emissor_offset"));
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"config/half_extents"),_SCS("set_emission_half_extents"),_SCS("get_emission_half_extents"));
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"config/local_space"),_SCS("set_use_local_space"),_SCS("is_using_local_space"));
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"config/explosiveness",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_explosiveness"),_SCS("get_explosiveness"));
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"config/flip_h"),_SCS("set_flip_h"),_SCS("is_flipped_h"));
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"config/flip_v"),_SCS("set_flip_v"),_SCS("is_flipped_v"));
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"config/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
- ADD_PROPERTY(PropertyInfo(Variant::INT,"config/h_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_h_frames"),_SCS("get_h_frames"));
- ADD_PROPERTY(PropertyInfo(Variant::INT,"config/v_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_v_frames"),_SCS("get_v_frames"));
-
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL,"config/time_scale",PROPERTY_HINT_EXP_RANGE,"0.01,128,0.01"),_SCS("set_time_scale"),_SCS("get_time_scale") );
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/preprocess",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),_SCS("set_pre_process_time"),_SCS("get_pre_process_time") );
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/emit_timeout",PROPERTY_HINT_RANGE,"0,3600,0.1"),_SCS("set_emit_timeout"),_SCS("get_emit_timeout") );
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/emitting"),_SCS("set_emitting"),_SCS("is_emitting") );
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/offset"),_SCS("set_emissor_offset"),_SCS("get_emissor_offset"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/half_extents"),_SCS("set_emission_half_extents"),_SCS("get_emission_half_extents"));
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/local_space"),_SCS("set_use_local_space"),_SCS("is_using_local_space"));
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL,"config/explosiveness",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_explosiveness"),_SCS("get_explosiveness"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL,"config/flip_h"),_SCS("set_flip_h"),_SCS("is_flipped_h"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL,"config/flip_v"),_SCS("set_flip_v"),_SCS("is_flipped_v"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"config/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT,"config/h_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_h_frames"),_SCS("get_h_frames"));
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT,"config/v_frames",PROPERTY_HINT_RANGE,"1,512,1"),_SCS("set_v_frames"),_SCS("get_v_frames"));
for(int i=0;i<PARAM_MAX;i++) {
@@ -1061,19 +1092,22 @@ void Particles2D::_bind_methods() {
}
for(int i=0;i<PARAM_MAX;i++) {
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,_particlesframe_property_rnames[i],PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_randomness"),_SCS("get_randomness"),i);
+ ADD_PROPERTYINZ(PropertyInfo(Variant::REAL,_particlesframe_property_rnames[i],PROPERTY_HINT_RANGE,"-1,1,0.01"),_SCS("set_randomness"),_SCS("get_randomness"),i);
}
- ADD_PROPERTY( PropertyInfo( Variant::INT, "color_phases/count",PROPERTY_HINT_RANGE,"0,4,1"), _SCS("set_color_phases"), _SCS("get_color_phases"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "color_phases/count",PROPERTY_HINT_RANGE,"0,4,1", 0), _SCS("set_color_phases"), _SCS("get_color_phases"));
+ //Backward compatibility. They will be converted to color ramp
for(int i=0;i<MAX_COLOR_PHASES;i++) {
String phase="phase_"+itos(i)+"/";
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, phase+"pos", PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_color_phase_pos"),_SCS("get_color_phase_pos"),i );
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, phase+"color"),_SCS("set_color_phase_color"),_SCS("get_color_phase_color"),i );
+ ADD_PROPERTYI( PropertyInfo( Variant::REAL, phase+"pos", PROPERTY_HINT_RANGE,"0,1,0.01", 0),_SCS("set_color_phase_pos"),_SCS("get_color_phase_pos"),i );
+ ADD_PROPERTYI( PropertyInfo( Variant::COLOR, phase+"color", PROPERTY_HINT_NONE, "", 0),_SCS("set_color_phase_color"),_SCS("get_color_phase_color"),i );
}
+ ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "color/color"),_SCS("set_color"),_SCS("get_color"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"color/color_ramp",PROPERTY_HINT_RESOURCE_TYPE,"ColorRamp"),_SCS("set_color_ramp"),_SCS("get_color_ramp"));
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2_ARRAY,"emission_points",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_emission_points"),_SCS("get_emission_points"));
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2_ARRAY,"emission_points",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_emission_points"),_SCS("get_emission_points"));
BIND_CONSTANT( PARAM_DIRECTION );
BIND_CONSTANT( PARAM_SPREAD );
@@ -1097,8 +1131,6 @@ void Particles2D::_bind_methods() {
}
-
-
Particles2D::Particles2D() {
for(int i=0;i<PARAM_MAX;i++) {
@@ -1118,6 +1150,7 @@ Particles2D::Particles2D() {
set_param(PARAM_FINAL_SIZE,1.0);
set_param(PARAM_ANIM_SPEED_SCALE,1.0);
+ set_color(Color(1,1,1,1));
time=0;
lifetime=2;
@@ -1129,17 +1162,6 @@ Particles2D::Particles2D() {
preprocess=0;
time_scale=1.0;
- color_phase_count=1;
-
- set_color_phase_pos(0,0.0);
- set_color_phase_pos(1,1.0);
- set_color_phase_pos(2,1.0);
- set_color_phase_pos(3,1.0);
-
- set_color_phase_color(0,Color(1,1,1));
- set_color_phase_color(1,Color(0,0,0));
- set_color_phase_color(2,Color(0,0,0));
- set_color_phase_color(3,Color(0,0,0));
flip_h=false;
flip_v=false;
diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h
index 90b5a188a6..4ee0fcf8da 100644
--- a/scene/2d/particles_2d.h
+++ b/scene/2d/particles_2d.h
@@ -31,6 +31,7 @@
#include "scene/2d/node_2d.h"
#include "scene/resources/texture.h"
+#include "scene/resources/color_ramp.h"
class Particles2D;
class ParticleAttractor2D : public Node2D {
@@ -125,11 +126,6 @@ private:
};
Vector<Particle> particles;
- int color_phase_count;
- struct ColorPhase {
- Color color;
- float pos;
- } color_phases[MAX_COLOR_PHASES];
struct AttractorCache {
@@ -161,6 +157,9 @@ private:
Ref<Texture> texture;
+ //If no color ramp is set then default color is used. Created as simple alternative to color_ramp.
+ Color default_color;
+ Ref<ColorRamp> color_ramp;
void testee(int a, int b, int c, int d, int e);
void _process_particles(float p_delta);
@@ -230,6 +229,12 @@ public:
void set_texture(const Ref<Texture>& p_texture);
Ref<Texture> get_texture() const;
+ void set_color(const Color& p_color);
+ Color get_color() const;
+
+ void set_color_ramp(const Ref<ColorRamp>& p_texture);
+ Ref<ColorRamp> get_color_ramp() const;
+
void set_emissor_offset(const Point2& p_offset);
Point2 get_emissor_offset() const;
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index 7ba1bb28b6..8f110b3931 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -118,7 +118,7 @@ void PathFollow2D::_update_transform() {
pos+=n*h_offset;
pos+=t*v_offset;
- set_rot(t.atan2());
+ set_rot(t.angle());
} else {
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 9fd4a25e7f..c30921eb69 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -68,18 +68,40 @@ float PhysicsBody2D::get_one_way_collision_max_depth() const{
}
+void PhysicsBody2D::_set_layers(uint32_t p_mask) {
+
+ set_layer_mask(p_mask);
+ set_collision_mask(p_mask);
+}
+
+uint32_t PhysicsBody2D::_get_layers() const{
+
+ return get_layer_mask();
+}
+
void PhysicsBody2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&PhysicsBody2D::set_layer_mask);
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&PhysicsBody2D::get_layer_mask);
ObjectTypeDB::bind_method(_MD("set_collision_mask","mask"),&PhysicsBody2D::set_collision_mask);
ObjectTypeDB::bind_method(_MD("get_collision_mask"),&PhysicsBody2D::get_collision_mask);
+
+
+ ObjectTypeDB::bind_method(_MD("set_collision_mask_bit","bit","value"),&PhysicsBody2D::set_collision_mask_bit);
+ ObjectTypeDB::bind_method(_MD("get_collision_mask_bit","bit"),&PhysicsBody2D::get_collision_mask_bit);
+
+ ObjectTypeDB::bind_method(_MD("set_layer_mask_bit","bit","value"),&PhysicsBody2D::set_layer_mask_bit);
+ ObjectTypeDB::bind_method(_MD("get_layer_mask_bit","bit"),&PhysicsBody2D::get_layer_mask_bit);
+
+ ObjectTypeDB::bind_method(_MD("_set_layers","mask"),&PhysicsBody2D::_set_layers);
+ ObjectTypeDB::bind_method(_MD("_get_layers"),&PhysicsBody2D::_get_layers);
ObjectTypeDB::bind_method(_MD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction);
ObjectTypeDB::bind_method(_MD("get_one_way_collision_direction"),&PhysicsBody2D::get_one_way_collision_direction);
ObjectTypeDB::bind_method(_MD("set_one_way_collision_max_depth","depth"),&PhysicsBody2D::set_one_way_collision_max_depth);
ObjectTypeDB::bind_method(_MD("get_one_way_collision_max_depth"),&PhysicsBody2D::get_one_way_collision_max_depth);
ObjectTypeDB::bind_method(_MD("add_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::add_collision_exception_with);
ObjectTypeDB::bind_method(_MD("remove_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::remove_collision_exception_with);
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"layers",PROPERTY_HINT_ALL_FLAGS,"",0),_SCS("_set_layers"),_SCS("_get_layers")); //for backwards compat
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"collision/mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_mask"),_SCS("get_collision_mask"));
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"one_way_collision/direction"),_SCS("set_one_way_collision_direction"),_SCS("get_one_way_collision_direction"));
@@ -108,6 +130,37 @@ uint32_t PhysicsBody2D::get_collision_mask() const {
return collision_mask;
}
+void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) {
+
+ uint32_t mask = get_collision_mask();
+ if (p_value)
+ mask|=1<<p_bit;
+ else
+ mask&=~(1<<p_bit);
+ set_collision_mask(mask);
+
+}
+bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const{
+
+ return get_collision_mask()&(1<<p_bit);
+}
+
+
+void PhysicsBody2D::set_layer_mask_bit(int p_bit, bool p_value) {
+
+ uint32_t mask = get_layer_mask();
+ if (p_value)
+ mask|=1<<p_bit;
+ else
+ mask&=~(1<<p_bit);
+ set_layer_mask(mask);
+
+}
+
+bool PhysicsBody2D::get_layer_mask_bit(int p_bit) const{
+
+ return get_layer_mask()&(1<<p_bit);
+}
PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) {
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index b6be07500f..b70fdd59cf 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -42,6 +42,11 @@ class PhysicsBody2D : public CollisionObject2D {
uint32_t collision_mask;
Vector2 one_way_collision_direction;
float one_way_collision_max_depth;
+
+
+ void _set_layers(uint32_t p_mask);
+ uint32_t _get_layers() const;
+
protected:
void _notification(int p_what);
@@ -56,6 +61,13 @@ public:
void set_collision_mask(uint32_t p_mask);
uint32_t get_collision_mask() const;
+
+ void set_collision_mask_bit(int p_bit, bool p_value);
+ bool get_collision_mask_bit(int p_bit) const;
+
+ void set_layer_mask_bit(int p_bit, bool p_value);
+ bool get_layer_mask_bit(int p_bit) const;
+
void add_collision_exception_with(Node* p_node); //must be physicsbody
void remove_collision_exception_with(Node* p_node);
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 20abe42cd9..4a199e3418 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -53,6 +53,16 @@ uint32_t RayCast2D::get_layer_mask() const {
return layer_mask;
}
+void RayCast2D::set_type_mask(uint32_t p_mask) {
+
+ type_mask=p_mask;
+}
+
+uint32_t RayCast2D::get_type_mask() const {
+
+ return type_mask;
+}
+
bool RayCast2D::is_colliding() const{
return collided;
@@ -115,17 +125,17 @@ void RayCast2D::_notification(int p_what) {
set_fixed_process(false);
} break;
-#ifdef TOOLS_ENABLED
+
case NOTIFICATION_DRAW: {
- if (!get_tree()->is_editor_hint())
+ if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
break;
Matrix32 xf;
- xf.rotate(cast_to.atan2());
+ xf.rotate(cast_to.angle());
xf.translate(Vector2(0,cast_to.length()));
//Vector2 tip = Vector2(0,s->get_length());
- Color dcol(0.9,0.2,0.2,0.4);
+ Color dcol=get_tree()->get_debug_collisions_color();//0.9,0.2,0.2,0.4);
draw_line(Vector2(),cast_to,dcol,3);
Vector<Vector2> pts;
float tsize=4;
@@ -139,7 +149,7 @@ void RayCast2D::_notification(int p_what) {
draw_primitive(pts,cols,Vector<Vector2>()); //small arrow
} break;
-#endif
+
case NOTIFICATION_FIXED_PROCESS: {
@@ -162,7 +172,7 @@ void RayCast2D::_notification(int p_what) {
Physics2DDirectSpaceState::RayResult rr;
- if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask)) {
+ if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask,type_mask)) {
collided=true;
against=rr.collider_id;
@@ -241,9 +251,13 @@ void RayCast2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_layer_mask","mask"),&RayCast2D::set_layer_mask);
ObjectTypeDB::bind_method(_MD("get_layer_mask"),&RayCast2D::get_layer_mask);
+ ObjectTypeDB::bind_method(_MD("set_type_mask","mask"),&RayCast2D::set_type_mask);
+ ObjectTypeDB::bind_method(_MD("get_type_mask"),&RayCast2D::get_type_mask);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"cast_to"),_SCS("set_cast_to"),_SCS("get_cast_to"));
ADD_PROPERTY(PropertyInfo(Variant::INT,"layer_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_layer_mask"),_SCS("get_layer_mask"));
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"type_mask",PROPERTY_HINT_FLAGS,"Static,Kinematic,Rigid,Character,Area"),_SCS("set_type_mask"),_SCS("get_type_mask"));
}
RayCast2D::RayCast2D() {
@@ -253,5 +267,6 @@ RayCast2D::RayCast2D() {
collided=false;
against_shape=0;
layer_mask=1;
+ type_mask=Physics2DDirectSpaceState::TYPE_MASK_COLLISION;
cast_to=Vector2(0,50);
}
diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h
index c7616be523..8c3ce8b3b3 100644
--- a/scene/2d/ray_cast_2d.h
+++ b/scene/2d/ray_cast_2d.h
@@ -44,6 +44,7 @@ class RayCast2D : public Node2D {
Vector2 collision_normal;
Set<RID> exclude;
uint32_t layer_mask;
+ uint32_t type_mask;
Vector2 cast_to;
@@ -62,6 +63,9 @@ public:
void set_layer_mask(uint32_t p_mask);
uint32_t get_layer_mask() const;
+ void set_type_mask(uint32_t p_mask);
+ uint32_t get_type_mask() const;
+
bool is_colliding() const;
Object *get_collider() const;
int get_collider_shape() const;
diff --git a/scene/2d/sample_player_2d.cpp b/scene/2d/sample_player_2d.cpp
index bb37475944..ec17ffc55e 100644
--- a/scene/2d/sample_player_2d.cpp
+++ b/scene/2d/sample_player_2d.cpp
@@ -214,7 +214,7 @@ void SamplePlayer2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_sample_library","library:SampleLibrary"),&SamplePlayer2D::set_sample_library);
ObjectTypeDB::bind_method(_MD("get_sample_library:SampleLibrary"),&SamplePlayer2D::get_sample_library);
- ObjectTypeDB::bind_method(_MD("set_polyphony","voices"),&SamplePlayer2D::set_polyphony);
+ ObjectTypeDB::bind_method(_MD("set_polyphony","max_voices"),&SamplePlayer2D::set_polyphony);
ObjectTypeDB::bind_method(_MD("get_polyphony"),&SamplePlayer2D::get_polyphony);
ObjectTypeDB::bind_method(_MD("play","sample","voice"),&SamplePlayer2D::play,DEFVAL(NEXT_VOICE));
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index 0c0a0d7822..89d9966958 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -30,6 +30,7 @@
#include "core/core_string_names.h"
#include "scene/scene_string_names.h"
#include "scene/main/viewport.h"
+#include "os/os.h"
void Sprite::edit_set_pivot(const Point2& p_pivot) {
@@ -82,9 +83,12 @@ void Sprite::_notification(int p_what) {
}
- Point2i ofs=offset;
+ Point2 ofs=offset;
if (centered)
ofs-=s/2;
+ if (OS::get_singleton()->get_use_pixel_snap()) {
+ ofs=ofs.floor();
+ }
Rect2 dst_rect(ofs,s);
@@ -103,14 +107,18 @@ void Sprite::set_texture(const Ref<Texture>& p_texture) {
if (p_texture==texture)
return;
+#ifdef DEBUG_ENABLED
if (texture.is_valid()) {
texture->disconnect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->update);
}
+#endif
texture=p_texture;
+#ifdef DEBUG_ENABLED
if (texture.is_valid()) {
texture->set_flags(texture->get_flags()); //remove repeat from texture, it looks bad in sprites
texture->connect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->update);
}
+#endif
update();
item_rect_changed();
}
@@ -185,6 +193,7 @@ void Sprite::set_region_rect(const Rect2& p_region_rect) {
if (region && changed) {
update();
item_rect_changed();
+ _change_notify("region_rect");
}
}
@@ -265,7 +274,7 @@ Rect2 Sprite::get_item_rect() const {
s=s/Point2(hframes,vframes);
}
- Point2i ofs=offset;
+ Point2 ofs=offset;
if (centered)
ofs-=s/2;
@@ -313,17 +322,17 @@ void Sprite::_bind_methods() {
ADD_SIGNAL(MethodInfo("frame_changed"));
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_texture"),_SCS("get_texture"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered"));
- ADD_PROPERTY( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_h"), _SCS("set_flip_h"),_SCS("is_flipped_h"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "flip_v"), _SCS("set_flip_v"),_SCS("is_flipped_v"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "vframes"), _SCS("set_vframes"),_SCS("get_vframes"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "hframes"), _SCS("set_hframes"),_SCS("get_hframes"));
- ADD_PROPERTY( PropertyInfo( Variant::INT, "frame"), _SCS("set_frame"),_SCS("get_frame"));
- ADD_PROPERTY( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "region"), _SCS("set_region"),_SCS("is_region"));
- ADD_PROPERTY( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_texture"),_SCS("get_texture"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_h"), _SCS("set_flip_h"),_SCS("is_flipped_h"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_v"), _SCS("set_flip_v"),_SCS("is_flipped_v"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::INT, "vframes",PROPERTY_HINT_RANGE,"1,16384,1"), _SCS("set_vframes"),_SCS("get_vframes"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::INT, "hframes",PROPERTY_HINT_RANGE,"1,16384,1"), _SCS("set_hframes"),_SCS("get_hframes"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), _SCS("set_frame"),_SCS("get_frame"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "region"), _SCS("set_region"),_SCS("is_region"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect"));
}
@@ -413,11 +422,14 @@ void ViewportSprite::_notification(int p_what) {
src_rect.size=s;
- Point2i ofs=offset;
+ Point2 ofs=offset;
if (centered)
ofs-=s/2;
- Rect2i dst_rect(ofs,s);
+ 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;
@@ -505,7 +517,7 @@ Rect2 ViewportSprite::get_item_rect() const {
Size2i s;
s = texture->get_size();
- Point2i ofs=offset;
+ Point2 ofs=offset;
if (centered)
ofs-=s/2;
@@ -530,10 +542,10 @@ void ViewportSprite::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_modulate","modulate"),&ViewportSprite::set_modulate);
ObjectTypeDB::bind_method(_MD("get_modulate"),&ViewportSprite::get_modulate);
- ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "viewport"), _SCS("set_viewport_path"),_SCS("get_viewport_path"));
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered"));
- ADD_PROPERTY( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset"));
- ADD_PROPERTY( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::NODE_PATH, "viewport"), _SCS("set_viewport_path"),_SCS("get_viewport_path"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), _SCS("set_centered"),_SCS("is_centered"));
+ ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), _SCS("set_offset"),_SCS("get_offset"));
+ ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate"));
}
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 2fca1e67e8..167b637bdc 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -30,6 +30,7 @@
#include "io/marshalls.h"
#include "servers/physics_2d_server.h"
#include "method_bind_ext.inc"
+#include "os/os.h"
int TileMap::_get_quadrant_size() const {
@@ -262,6 +263,14 @@ void TileMap::_update_dirty_quadrants() {
Vector2 qofs;
+ SceneTree *st=SceneTree::get_singleton();
+ Color debug_collision_color;
+
+ bool debug_shapes = st && st->is_debugging_collisions_hint();
+ if (debug_shapes) {
+ debug_collision_color=st->get_debug_collisions_color();
+ }
+
while (dirty_quadrant_list.first()) {
Quadrant &q = *dirty_quadrant_list.first()->self();
@@ -398,11 +407,19 @@ void TileMap::_update_dirty_quadrants() {
_fix_cell_transform(xform,c,shape_ofs+center_ofs,s);
- ps->body_add_shape(q.body,shape->get_rid(),xform);
+ if (debug_shapes) {
+ vs->canvas_item_add_set_transform(canvas_item,xform);
+ shape->draw(canvas_item,debug_collision_color);
+
+ }
+ 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));
}
}
+ if (debug_shapes) {
+ vs->canvas_item_add_set_transform(canvas_item,Matrix32());
+ }
if (navigation) {
Ref<NavigationPolygon> navpoly = tile_set->tile_get_navigation_polygon(c.id);
@@ -412,6 +429,7 @@ void TileMap::_update_dirty_quadrants() {
xform.set_origin(offset.floor()+q.pos);
_fix_cell_transform(xform,c,npoly_ofs+center_ofs,s);
+
int pid = navigation->navpoly_create(navpoly,nav_rel * xform);
Quadrant::NavPoly np;
@@ -579,6 +597,10 @@ void TileMap::_make_quadrant_dirty(Map<PosKey,Quadrant>::Element *Q) {
call_deferred("_update_dirty_quadrants");
}
+void TileMap::set_cellv(const Vector2& p_pos,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {
+
+ set_cell(p_pos.x,p_pos.y,p_tile,p_flip_x,p_flip_y,p_transpose);
+}
void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {
@@ -1009,13 +1031,12 @@ Vector2 TileMap::world_to_map(const Vector2& p_pos) const{
switch(half_offset) {
case HALF_OFFSET_X: {
- if (int(ret.y)&1) {
-
+ if ( ret.y > 0 ? int(ret.y)&1 : (int(ret.y)-1)&1 ) {
ret.x-=0.5;
}
} break;
case HALF_OFFSET_Y: {
- if (int(ret.x)&1) {
+ if ( ret.x > 0 ? int(ret.x)&1 : (int(ret.x)-1)&1) {
ret.y-=0.5;
}
} break;
@@ -1106,6 +1127,7 @@ void TileMap::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_collision_bounce"),&TileMap::get_collision_bounce);
ObjectTypeDB::bind_method(_MD("set_cell","x","y","tile","flip_x","flip_y","transpose"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false),DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("set_cellv","pos","tile","flip_x","flip_y","transpose"),&TileMap::set_cellv,DEFVAL(false),DEFVAL(false),DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_cell","x","y"),&TileMap::get_cell);
ObjectTypeDB::bind_method(_MD("is_cell_x_flipped","x","y"),&TileMap::is_cell_x_flipped);
ObjectTypeDB::bind_method(_MD("is_cell_y_flipped","x","y"),&TileMap::is_cell_y_flipped);
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index 84ca65da4f..60534cce15 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -207,6 +207,8 @@ public:
bool is_cell_y_flipped(int p_x,int p_y) const;
bool is_cell_transposed(int p_x,int p_y) const;
+ void set_cellv(const Vector2& p_pos,int p_tile,bool p_flip_x=false,bool p_flip_y=false,bool p_transpose=false);
+
Rect2 get_item_rect() const;
void set_collision_layer(uint32_t p_layer);
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index ea4b1fc7b0..dc72c9a267 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -155,6 +155,11 @@ void VisibilityEnabler2D::_screen_enter() {
_change_node_state(E->key(),true);
}
+ if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
+ get_parent()->set_fixed_process(true);
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+ get_parent()->set_process(true);
+
visible=true;
}
@@ -165,6 +170,11 @@ void VisibilityEnabler2D::_screen_exit(){
_change_node_state(E->key(),false);
}
+ if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
+ get_parent()->set_fixed_process(false);
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+ get_parent()->set_process(false);
+
visible=false;
}
@@ -235,6 +245,12 @@ void VisibilityEnabler2D::_notification(int p_what){
_find_nodes(from);
+ if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
+ get_parent()->set_fixed_process(false);
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
+ get_parent()->set_process(false);
+
+
}
if (p_what==NOTIFICATION_EXIT_TREE) {
@@ -317,10 +333,14 @@ void VisibilityEnabler2D::_bind_methods(){
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_animations"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_ANIMATIONS );
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/freeze_bodies"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_FREEZE_BODIES);
ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/pause_particles"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PAUSE_PARTICLES);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/process_parent"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PARENT_PROCESS);
+ ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"enabler/fixed_process_parent"),_SCS("set_enabler"),_SCS("is_enabler_enabled"), ENABLER_PARENT_FIXED_PROCESS);
BIND_CONSTANT( ENABLER_FREEZE_BODIES );
BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS );
BIND_CONSTANT( ENABLER_PAUSE_PARTICLES );
+ BIND_CONSTANT( ENABLER_PARENT_PROCESS );
+ BIND_CONSTANT( ENABLER_PARENT_FIXED_PROCESS );
BIND_CONSTANT( ENABLER_MAX);
}
@@ -341,6 +361,8 @@ VisibilityEnabler2D::VisibilityEnabler2D() {
for(int i=0;i<ENABLER_MAX;i++)
enabler[i]=true;
+ enabler[ENABLER_PARENT_PROCESS]=false;
+ enabler[ENABLER_PARENT_FIXED_PROCESS]=false;
visible=false;
diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h
index ce68724630..1f7e4c6d45 100644
--- a/scene/2d/visibility_notifier_2d.h
+++ b/scene/2d/visibility_notifier_2d.h
@@ -74,6 +74,8 @@ public:
ENABLER_PAUSE_ANIMATIONS,
ENABLER_FREEZE_BODIES,
ENABLER_PAUSE_PARTICLES,
+ ENABLER_PARENT_PROCESS,
+ ENABLER_PARENT_FIXED_PROCESS,
ENABLER_MAX
};