diff options
| author | Juan Linietsky | 2016-06-26 16:22:20 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2016-06-26 16:22:20 -0300 |
| commit | 282da142aea365680acd80c12916d8e46dd2f5e8 (patch) | |
| tree | 0e77c1b9c7d370412f2b7a7308dcc3259c73bc29 /scene/2d/parallax_layer.cpp | |
| parent | 33f1204dc4e919660bd923f366897349a9f9fdbb (diff) | |
| download | godot-282da142aea365680acd80c12916d8e46dd2f5e8.tar.gz godot-282da142aea365680acd80c12916d8e46dd2f5e8.tar.zst godot-282da142aea365680acd80c12916d8e46dd2f5e8.zip | |
Diffstat (limited to 'scene/2d/parallax_layer.cpp')
| -rw-r--r-- | scene/2d/parallax_layer.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index bf559deb0..ec7189ff9 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -32,6 +32,15 @@ void ParallaxLayer::set_motion_scale(const Size2& p_scale) { motion_scale=p_scale; + + + ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); + if (is_inside_tree() && pb) { + Vector2 ofs = pb->get_final_offset(); + float scale = pb->get_scroll_scale(); + set_base_offset_and_scale(ofs,scale); + } + } Size2 ParallaxLayer::get_motion_scale() const { @@ -40,6 +49,23 @@ Size2 ParallaxLayer::get_motion_scale() const { } +void ParallaxLayer::set_motion_offset(const Size2& p_offset) { + + motion_offset=p_offset; + + ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>(); + if (is_inside_tree() && pb) { + Vector2 ofs = pb->get_final_offset(); + float scale = pb->get_scroll_scale(); + set_base_offset_and_scale(ofs,scale); + } +} + +Size2 ParallaxLayer::get_motion_offset() const { + + return motion_offset; + +} void ParallaxLayer::_update_mirroring() { @@ -89,7 +115,7 @@ void ParallaxLayer::set_base_offset_and_scale(const Point2& p_offset,float p_sca return; if (get_tree()->is_editor_hint()) return; - Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale; + Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale+motion_offset; if (mirroring.x) { @@ -132,10 +158,13 @@ void ParallaxLayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_motion_scale","scale"),&ParallaxLayer::set_motion_scale); ObjectTypeDB::bind_method(_MD("get_motion_scale"),&ParallaxLayer::get_motion_scale); + ObjectTypeDB::bind_method(_MD("set_motion_offset","offset"),&ParallaxLayer::set_motion_offset); + ObjectTypeDB::bind_method(_MD("get_motion_offset"),&ParallaxLayer::get_motion_offset); ObjectTypeDB::bind_method(_MD("set_mirroring","mirror"),&ParallaxLayer::set_mirroring); ObjectTypeDB::bind_method(_MD("get_mirroring"),&ParallaxLayer::get_mirroring); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion/scale"),_SCS("set_motion_scale"),_SCS("get_motion_scale")); + ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion/offset"),_SCS("set_motion_offset"),_SCS("get_motion_offset")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion/mirroring"),_SCS("set_mirroring"),_SCS("get_mirroring")); } |
