diff options
| author | ShyRed | 2018-03-10 17:01:46 +0100 |
|---|---|---|
| committer | ShyRed | 2018-03-10 17:23:29 +0100 |
| commit | a23c0877f1bb26edb75aa344f1049a7b7a91f079 (patch) | |
| tree | a59fb710d69b989a6391affb80054f92a74e1621 /scene/2d/sprite.cpp | |
| parent | aeb1c67b5b55c769256a8ffc2f9d9095d6fc74da (diff) | |
| download | godot-a23c0877f1bb26edb75aa344f1049a7b7a91f079.tar.gz godot-a23c0877f1bb26edb75aa344f1049a7b7a91f079.tar.zst godot-a23c0877f1bb26edb75aa344f1049a7b7a91f079.zip | |
Diffstat (limited to 'scene/2d/sprite.cpp')
| -rw-r--r-- | scene/2d/sprite.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index e3fa1fdcb..67f016ae7 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -121,7 +121,15 @@ void Sprite::set_texture(const Ref<Texture> &p_texture) { if (p_texture == texture) return; + + if (texture.is_valid()) + texture->remove_change_receptor(this); + texture = p_texture; + + if (texture.is_valid()) + texture->add_change_receptor(this); + update(); emit_signal("texture_changed"); item_rect_changed(); @@ -362,6 +370,15 @@ void Sprite::_validate_property(PropertyInfo &property) const { } } +void Sprite::_changed_callback(Object *p_changed, const char *p_prop) { + + // Changes to the texture need to trigger an update to make + // the editor redraw the sprite with the updated texture. + if (texture.is_valid() && texture.ptr() == p_changed) { + update(); + } +} + void Sprite::_bind_methods() { ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Sprite::set_texture); @@ -436,3 +453,8 @@ Sprite::Sprite() { vframes = 1; hframes = 1; } + +Sprite::~Sprite() { + if (texture.is_valid()) + texture->remove_change_receptor(this); +} |
