summaryrefslogtreecommitdiff
path: root/scene/3d/sprite_3d.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-07-27 14:09:45 +0200
committerGitHub <noreply@github.com>2019-07-27 14:09:45 +0200
commit6c9ccf18f87a662e1994c870088a6beaaeeb0384 (patch)
tree1ec767bcbfeb83670b0ddd08e6b2c06935a6f3a4 /scene/3d/sprite_3d.cpp
parent94aabf56a0a22df689bc57c71981c0008eb40464 (diff)
parent11cb4eb3638b0f97e1efde1ac54a3c7a94ea9d1b (diff)
Merge pull request #25327 from groud/frame_row_column
Add frame_coords accessor to Sprite
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");