animated_sprite.h
1 /*************************************************************************/
2 /* animated_sprite.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef ANIMATED_SPRITE_H
30 #define ANIMATED_SPRITE_H
31 
32 #include "scene/2d/node_2d.h"
33 #include "scene/resources/texture.h"
34 
35 
36 class SpriteFrames : public Resource {
37 
38  OBJ_TYPE(SpriteFrames,Resource);
39 
40  Vector< Ref<Texture> > frames;
41 
42  Array _get_frames() const;
43  void _set_frames(const Array& p_frames);
44 protected:
45 
46  static void _bind_methods();
47 
48 public:
49 
50 
51  void add_frame(const Ref<Texture>& p_frame,int p_at_pos=-1);
52  int get_frame_count() const;
53  _FORCE_INLINE_ Ref<Texture> get_frame(int p_idx) const { ERR_FAIL_INDEX_V(p_idx,frames.size(),Ref<Texture>()); return frames[p_idx]; }
54  void set_frame(int p_idx,const Ref<Texture>& p_frame){ ERR_FAIL_INDEX(p_idx,frames.size()); frames[p_idx]=p_frame; }
55  void remove_frame(int p_idx);
56  void clear();
57 
58  SpriteFrames();
59 
60 };
61 
62 
63 
64 class AnimatedSprite : public Node2D {
65 
66  OBJ_TYPE(AnimatedSprite,Node2D);
67 
68  Ref<SpriteFrames> frames;
69  int frame;
70 
71  bool centered;
72  Point2 offset;
73 
74  bool hflip;
75  bool vflip;
76 
77  Color modulate;
78 
79  void _res_changed();
80 protected:
81 
82  static void _bind_methods();
83  void _notification(int p_what);
84 
85 public:
86 
87 
88  virtual void edit_set_pivot(const Point2& p_pivot);
89  virtual Point2 edit_get_pivot() const;
90  virtual bool edit_has_pivot() const;
91 
92  void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
93  Ref<SpriteFrames> get_sprite_frames() const;
94 
95  void set_frame(int p_frame);
96  int get_frame() const;
97 
98  void set_centered(bool p_center);
99  bool is_centered() const;
100 
101  void set_offset(const Point2& p_offset);
102  Point2 get_offset() const;
103 
104  void set_flip_h(bool p_flip);
105  bool is_flipped_h() const;
106 
107  void set_flip_v(bool p_flip);
108  bool is_flipped_v() const;
109 
110  void set_modulate(const Color& p_color);
111  Color get_modulate() const;
112 
113  virtual Rect2 get_item_rect() const;
114 
115 
116  AnimatedSprite();
117 };
118 
119 #endif // ANIMATED_SPRITE_H
Definition: array.h:38
Definition: color.h:37
Definition: math_2d.h:204
Definition: resource.h:89
Definition: animated_sprite.h:36
Definition: math_2d.h:65
Definition: animated_sprite.h:64
Definition: node_2d.h:34
Definition: vector.h:43