mirror of
https://github.com/godotengine/godot.git
synced 2024-11-11 06:33:10 +00:00
Adds a speed factor to AnimatedSprite
This commit is contained in:
parent
e5a13e2626
commit
89fe7e2f92
@ -351,7 +351,7 @@ void AnimatedSprite::_notification(int p_what) {
|
|||||||
if (frame < 0)
|
if (frame < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float speed = frames->get_animation_speed(animation);
|
float speed = frames->get_animation_speed(animation) * speed_scale;
|
||||||
if (speed == 0)
|
if (speed == 0)
|
||||||
return; //do nothing
|
return; //do nothing
|
||||||
|
|
||||||
@ -481,6 +481,16 @@ int AnimatedSprite::get_frame() const {
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnimatedSprite::set_speed_scale(float p_speed_scale) {
|
||||||
|
|
||||||
|
speed_scale = MAX(p_speed_scale, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
float AnimatedSprite::get_speed_scale() const {
|
||||||
|
|
||||||
|
return speed_scale;
|
||||||
|
}
|
||||||
|
|
||||||
void AnimatedSprite::set_centered(bool p_center) {
|
void AnimatedSprite::set_centered(bool p_center) {
|
||||||
|
|
||||||
centered = p_center;
|
centered = p_center;
|
||||||
@ -570,7 +580,7 @@ void AnimatedSprite::_reset_timeout() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (frames.is_valid() && frames->has_animation(animation)) {
|
if (frames.is_valid() && frames->has_animation(animation)) {
|
||||||
float speed = frames->get_animation_speed(animation);
|
float speed = frames->get_animation_speed(animation) * speed_scale;
|
||||||
if (speed > 0) {
|
if (speed > 0) {
|
||||||
timeout = 1.0 / speed;
|
timeout = 1.0 / speed;
|
||||||
} else {
|
} else {
|
||||||
@ -636,6 +646,9 @@ void AnimatedSprite::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite::set_frame);
|
ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite::set_frame);
|
||||||
ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite::get_frame);
|
ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite::get_frame);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite::set_speed_scale);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite::get_speed_scale);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite::_res_changed);
|
ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite::_res_changed);
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("frame_changed"));
|
ADD_SIGNAL(MethodInfo("frame_changed"));
|
||||||
@ -644,6 +657,7 @@ void AnimatedSprite::_bind_methods() {
|
|||||||
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
|
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation");
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation");
|
||||||
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
|
ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
|
||||||
|
ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "speed_scale"), "set_speed_scale", "get_speed_scale");
|
||||||
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing");
|
ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing");
|
||||||
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
|
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
|
||||||
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
|
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
|
||||||
@ -658,6 +672,7 @@ AnimatedSprite::AnimatedSprite() {
|
|||||||
vflip = false;
|
vflip = false;
|
||||||
|
|
||||||
frame = 0;
|
frame = 0;
|
||||||
|
speed_scale = 1.0f;
|
||||||
playing = false;
|
playing = false;
|
||||||
animation = "default";
|
animation = "default";
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
@ -129,6 +129,7 @@ class AnimatedSprite : public Node2D {
|
|||||||
bool playing;
|
bool playing;
|
||||||
StringName animation;
|
StringName animation;
|
||||||
int frame;
|
int frame;
|
||||||
|
float speed_scale;
|
||||||
|
|
||||||
bool centered;
|
bool centered;
|
||||||
Point2 offset;
|
Point2 offset;
|
||||||
@ -172,6 +173,9 @@ public:
|
|||||||
void set_frame(int p_frame);
|
void set_frame(int p_frame);
|
||||||
int get_frame() const;
|
int get_frame() const;
|
||||||
|
|
||||||
|
void set_speed_scale(float p_speed_scale);
|
||||||
|
float get_speed_scale() const;
|
||||||
|
|
||||||
void set_centered(bool p_center);
|
void set_centered(bool p_center);
|
||||||
bool is_centered() const;
|
bool is_centered() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user