| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/resources/texture.h" |
| 34 |
|
| 35 |
class AnimatedTexture : public Texture2D { |
| 36 |
GDCLASS(AnimatedTexture, Texture2D); |
| 37 |
|
| 38 |
|
| 39 |
RWLock rw_lock; |
| 40 |
|
| 41 |
public: |
| 42 |
enum { |
| 43 |
MAX_FRAMES = 256 |
| 44 |
}; |
| 45 |
|
| 46 |
private: |
| 47 |
RID proxy_ph; |
| 48 |
RID proxy; |
| 49 |
|
| 50 |
struct Frame { |
| 51 |
Ref<Texture2D> texture; |
| 52 |
float duration = 1.0; |
| 53 |
}; |
| 54 |
|
| 55 |
Frame frames[MAX_FRAMES]; |
| 56 |
int frame_count = 1.0; |
| 57 |
int current_frame = 0; |
| 58 |
bool pause = false; |
| 59 |
bool one_shot = false; |
| 60 |
float speed_scale = 1.0; |
| 61 |
|
| 62 |
float time = 0.0; |
| 63 |
|
| 64 |
uint64_t prev_ticks = 0; |
| 65 |
|
| 66 |
void _update_proxy(); |
| 67 |
void _finish_non_thread_safe_setup(); |
| 68 |
|
| 69 |
protected: |
| 70 |
static void _bind_methods(); |
| 71 |
void _validate_property(PropertyInfo &p_property) const; |
| 72 |
|
| 73 |
public: |
| 74 |
void set_frames(int p_frames); |
| 75 |
int get_frames() const; |
| 76 |
|
| 77 |
void set_current_frame(int p_frame); |
| 78 |
int get_current_frame() const; |
| 79 |
|
| 80 |
void set_pause(bool p_pause); |
| 81 |
bool get_pause() const; |
| 82 |
|
| 83 |
void set_one_shot(bool p_one_shot); |
| 84 |
bool get_one_shot() const; |
| 85 |
|
| 86 |
void set_frame_texture(int p_frame, const Ref<Texture2D> &p_texture); |
| 87 |
Ref<Texture2D> get_frame_texture(int p_frame) const; |
| 88 |
|
| 89 |
void set_frame_duration(int p_frame, float p_duration); |
| 90 |
float get_frame_duration(int p_frame) const; |
| 91 |
|
| 92 |
void set_speed_scale(float p_scale); |
| 93 |
float get_speed_scale() const; |
| 94 |
|
| 95 |
virtual int get_width() const override; |
| 96 |
virtual int get_height() const override; |
| 97 |
virtual RID get_rid() const override; |
| 98 |
|
| 99 |
virtual bool has_alpha() const override; |
| 100 |
|
| 101 |
virtual Ref<Image> get_image() const override; |
| 102 |
|
| 103 |
bool is_pixel_opaque(int p_x, int p_y) const override; |
| 104 |
|
| 105 |
AnimatedTexture(); |
| 106 |
~AnimatedTexture(); |
| 107 |
}; |