1 /** 2 2D sprite node in 3D world, that can use multiple 2D textures for animation. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.animatedsprite3d; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.spritebase3d; 25 import godot.spriteframes; 26 /** 27 2D sprite node in 3D world, that can use multiple 2D textures for animation. 28 29 Animations are created using a $(D SpriteFrames) resource, which can be configured in the editor via the SpriteFrames panel. 30 */ 31 @GodotBaseClass struct AnimatedSprite3D 32 { 33 package(godot) enum string _GODOT_internal_name = "AnimatedSprite3D"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ SpriteBase3D _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 @GodotName("_is_playing") GodotMethod!(bool) _isPlaying; 44 @GodotName("_res_changed") GodotMethod!(void) _resChanged; 45 @GodotName("_set_playing") GodotMethod!(void, bool) _setPlaying; 46 @GodotName("get_animation") GodotMethod!(String) getAnimation; 47 @GodotName("get_frame") GodotMethod!(long) getFrame; 48 @GodotName("get_sprite_frames") GodotMethod!(SpriteFrames) getSpriteFrames; 49 @GodotName("is_playing") GodotMethod!(bool) isPlaying; 50 @GodotName("play") GodotMethod!(void, String) play; 51 @GodotName("set_animation") GodotMethod!(void, String) setAnimation; 52 @GodotName("set_frame") GodotMethod!(void, long) setFrame; 53 @GodotName("set_sprite_frames") GodotMethod!(void, SpriteFrames) setSpriteFrames; 54 @GodotName("stop") GodotMethod!(void) stop; 55 } 56 /// 57 pragma(inline, true) bool opEquals(in AnimatedSprite3D other) const 58 { return _godot_object.ptr is other._godot_object.ptr; } 59 /// 60 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 61 { _godot_object.ptr = n; return null; } 62 /// 63 pragma(inline, true) bool opEquals(typeof(null) n) const 64 { return _godot_object.ptr is n; } 65 /// 66 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 67 mixin baseCasts; 68 /// Construct a new instance of AnimatedSprite3D. 69 /// Note: use `memnew!AnimatedSprite3D` instead. 70 static AnimatedSprite3D _new() 71 { 72 static godot_class_constructor constructor; 73 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AnimatedSprite3D"); 74 if(constructor is null) return typeof(this).init; 75 return cast(AnimatedSprite3D)(constructor()); 76 } 77 @disable new(size_t s); 78 /** 79 80 */ 81 bool _isPlaying() const 82 { 83 Array _GODOT_args = Array.make(); 84 String _GODOT_method_name = String("_is_playing"); 85 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 86 } 87 /** 88 89 */ 90 void _resChanged() 91 { 92 Array _GODOT_args = Array.make(); 93 String _GODOT_method_name = String("_res_changed"); 94 this.callv(_GODOT_method_name, _GODOT_args); 95 } 96 /** 97 98 */ 99 void _setPlaying(in bool playing) 100 { 101 Array _GODOT_args = Array.make(); 102 _GODOT_args.append(playing); 103 String _GODOT_method_name = String("_set_playing"); 104 this.callv(_GODOT_method_name, _GODOT_args); 105 } 106 /** 107 108 */ 109 String getAnimation() const 110 { 111 checkClassBinding!(typeof(this))(); 112 return ptrcall!(String)(GDNativeClassBinding.getAnimation, _godot_object); 113 } 114 /** 115 116 */ 117 long getFrame() const 118 { 119 checkClassBinding!(typeof(this))(); 120 return ptrcall!(long)(GDNativeClassBinding.getFrame, _godot_object); 121 } 122 /** 123 124 */ 125 Ref!SpriteFrames getSpriteFrames() const 126 { 127 checkClassBinding!(typeof(this))(); 128 return ptrcall!(SpriteFrames)(GDNativeClassBinding.getSpriteFrames, _godot_object); 129 } 130 /** 131 Returns `true` if an animation is currently being played. 132 */ 133 bool isPlaying() const 134 { 135 checkClassBinding!(typeof(this))(); 136 return ptrcall!(bool)(GDNativeClassBinding.isPlaying, _godot_object); 137 } 138 /** 139 Plays the animation named `anim`. If no `anim` is provided, the current animation is played. 140 */ 141 void play(in String anim = gs!"") 142 { 143 checkClassBinding!(typeof(this))(); 144 ptrcall!(void)(GDNativeClassBinding.play, _godot_object, anim); 145 } 146 /** 147 148 */ 149 void setAnimation(in String animation) 150 { 151 checkClassBinding!(typeof(this))(); 152 ptrcall!(void)(GDNativeClassBinding.setAnimation, _godot_object, animation); 153 } 154 /** 155 156 */ 157 void setFrame(in long frame) 158 { 159 checkClassBinding!(typeof(this))(); 160 ptrcall!(void)(GDNativeClassBinding.setFrame, _godot_object, frame); 161 } 162 /** 163 164 */ 165 void setSpriteFrames(SpriteFrames sprite_frames) 166 { 167 checkClassBinding!(typeof(this))(); 168 ptrcall!(void)(GDNativeClassBinding.setSpriteFrames, _godot_object, sprite_frames); 169 } 170 /** 171 Stops the current animation (does not reset the frame counter). 172 */ 173 void stop() 174 { 175 checkClassBinding!(typeof(this))(); 176 ptrcall!(void)(GDNativeClassBinding.stop, _godot_object); 177 } 178 /** 179 The current animation from the `frames` resource. If this value changes, the `frame` counter is reset. 180 */ 181 @property String animation() 182 { 183 return getAnimation(); 184 } 185 /// ditto 186 @property void animation(String v) 187 { 188 setAnimation(v); 189 } 190 /** 191 The displayed animation frame's index. 192 */ 193 @property long frame() 194 { 195 return getFrame(); 196 } 197 /// ditto 198 @property void frame(long v) 199 { 200 setFrame(v); 201 } 202 /** 203 The $(D SpriteFrames) resource containing the animation(s). 204 */ 205 @property SpriteFrames frames() 206 { 207 return getSpriteFrames(); 208 } 209 /// ditto 210 @property void frames(SpriteFrames v) 211 { 212 setSpriteFrames(v); 213 } 214 /** 215 If `true`, the $(D animation) is currently playing. 216 */ 217 @property bool playing() 218 { 219 return _isPlaying(); 220 } 221 /// ditto 222 @property void playing(bool v) 223 { 224 _setPlaying(v); 225 } 226 }