summaryrefslogtreecommitdiff
path: root/scene/3d/sprite_3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/sprite_3d.cpp')
-rw-r--r--scene/3d/sprite_3d.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index b39762fde8..fc5523633d 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -564,6 +564,9 @@ void Sprite3D::set_frame(int p_frame) {
frame = p_frame;
_queue_update();
+
+ _change_notify("frame");
+ _change_notify("frame_coords");
emit_signal(SceneStringNames::get_singleton()->frame_changed);
}
@@ -572,6 +575,17 @@ int Sprite3D::get_frame() const {
return frame;
}
+void Sprite3D::set_frame_coords(const Vector2 &p_coord) {
+ ERR_FAIL_INDEX(int(p_coord.x), vframes);
+ ERR_FAIL_INDEX(int(p_coord.y), hframes);
+
+ set_frame(int(p_coord.y) * hframes + int(p_coord.x));
+}
+
+Vector2 Sprite3D::get_frame_coords() const {
+ return Vector2(frame % hframes, frame / hframes);
+}
+
void Sprite3D::set_vframes(int p_amount) {
ERR_FAIL_COND(p_amount < 1);
@@ -648,6 +662,9 @@ void Sprite3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_frame", "frame"), &Sprite3D::set_frame);
ClassDB::bind_method(D_METHOD("get_frame"), &Sprite3D::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame_coords", "coords"), &Sprite3D::set_frame_coords);
+ ClassDB::bind_method(D_METHOD("get_frame_coords"), &Sprite3D::get_frame_coords);
+
ClassDB::bind_method(D_METHOD("set_vframes", "vframes"), &Sprite3D::set_vframes);
ClassDB::bind_method(D_METHOD("get_vframes"), &Sprite3D::get_vframes);
@@ -659,6 +676,7 @@ void Sprite3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "vframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_vframes", "get_vframes");
ADD_PROPERTY(PropertyInfo(Variant::INT, "hframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_hframes", "get_hframes");
ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "frame_coords", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_frame_coords", "get_frame_coords");
ADD_GROUP("Region", "region_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "region_enabled"), "set_region", "is_region");
ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect");