Game Develop C++ Platform: SpriteObject.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
SpriteObject.h
Go to the documentation of this file.
1
6 #ifndef SPRITEOBJECT_H
7 #define SPRITEOBJECT_H
8
9 #include "GDCpp/Object.h"
10 #include "GDCpp/RuntimeObject.h"
11 namespace gd { class InitialInstance; }
12 namespace gd { class Object; }
13 namespace gd { class Layout; }
14 namespace sf { class Sprite; }
15 class Animation;
16 class Sprite;
17 class RuntimeScene;
18 #if defined(GD_IDE_ONLY)
19 class wxBitmap;
20 class wxWindow;
21 namespace gd { class MainFrameWrapper; }
22 #endif
23
28 class GD_API AnimationProxy
29 {
30 public:
31 AnimationProxy();
32 AnimationProxy(const Animation & animation);
33 virtual ~AnimationProxy();
34 AnimationProxy(const AnimationProxy & proxy);
35 AnimationProxy & operator=(const AnimationProxy & rhs);
36
37 Animation & Get() {return *animation; }
38 const Animation & Get() const {return *animation; }
39 Animation & GetNonConst() {return *animation; }
40
41 private:
42 Animation * animation;
43 };
44
55 class GD_API SpriteObject : public gd::Object
56 {
57 public :
58
59 SpriteObject(std::string name_);
60 virtual ~SpriteObject();
61 virtual gd::Object * Clone() const { return new SpriteObject(*this);}
62
63 #if defined(GD_IDE_ONLY)
64 virtual bool GenerateThumbnail(const gd::Project & project, wxBitmap & thumbnail) const;
65 virtual void ExposeResources(gd::ArbitraryResourceWorker & worker);
66
67 virtual void EditObject( wxWindow* parent, gd::Project & project, gd::MainFrameWrapper & mainFrameWrapper_ );
68 virtual std::map<std::string, std::string> GetInitialInstanceProperties(const gd::InitialInstance & position, gd::Project & project, gd::Layout & scene);
69 virtual bool UpdateInitialInstanceProperty(gd::InitialInstance & position, const std::string & name, const std::string & value, gd::Project & project, gd::Layout & scene);
70 virtual void DrawInitialInstance(gd::InitialInstance & instance, sf::RenderTarget & renderTarget, gd::Project & project, gd::Layout & layout);
71 virtual sf::Vector2f GetInitialInstanceDefaultSize(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const;
72 virtual sf::Vector2f GetInitialInstanceOrigin(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout) const;
73 virtual void LoadResources(gd::Project & project, gd::Layout & layout);
74
75 virtual bool SupportShaders() { return true; }
76 #endif
77
81 inline const Animation & GetAnimation(unsigned int nb) const { if ( nb >= GetAnimationCount() ) return badAnimation; else return animations[nb].Get(); }
83 inline Animation & GetAnimation(unsigned int nb) { if ( nb >= GetAnimationCount() ) return badAnimation; else return animations[nb].Get(); }
84 unsigned int GetAnimationCount() const {return animations.size();};
85 void AddAnimation(const Animation & animation);
86 bool RemoveAnimation(unsigned int nb);
87 inline void RemoveAllAnimation() { animations.clear(); }
88 inline bool HasNoAnimations() const { return animations.empty(); }
89 inline const std::vector < AnimationProxy > & GetAllAnimations() const { return animations; }
91
92 private:
93
94 virtual void DoLoadFromXml(gd::Project & project, const TiXmlElement * elemScene);
95 #if defined(GD_IDE_ONLY)
96 virtual void DoSaveToXml(TiXmlElement * elemScene);
97 #endif
98
99 const Sprite * GetInitialInstanceSprite(gd::InitialInstance & instance, gd::Project & project, gd::Layout & layout, bool * shouldNotRotate = NULL) const;
100 mutable std::vector < AnimationProxy > animations;
101
102 //Null objects if need to return a bad object.
103 static Animation badAnimation;
104 };
105
106 class GD_API RuntimeSpriteObject : public RuntimeObject
107 {
108 public :
109
110 RuntimeSpriteObject(RuntimeScene & scene, const gd::Object & object);
111 virtual ~RuntimeSpriteObject() {};
112 virtual RuntimeObject * Clone() const { return new RuntimeSpriteObject(*this);}
113
114 virtual bool ExtraInitializationFromInitialInstance(const gd::InitialInstance & position);
115
116 virtual bool Draw(sf::RenderTarget & renderTarget);
117
118 #if defined(GD_IDE_ONLY)
119 virtual void GetPropertyForDebugger (unsigned int propertyNb, std::string & name, std::string & value) const;
120 virtual bool ChangeProperty(unsigned int propertyNb, std::string newValue);
121 virtual unsigned int GetNumberOfProperties() const;
122 #endif
123
124 virtual void UpdateTime(float timeElapsed);
125
126 virtual void OnPositionChanged() {needUpdateCurrentSprite = true;};
127
128 virtual float GetWidth() const;
129 virtual float GetHeight() const;
130 virtual void SetWidth(float newWidth);
131 virtual void SetHeight(float newHeight);
132 virtual void SetOriginalSize();
133
134 virtual float GetDrawableX() const;
135 virtual float GetDrawableY() const;
136
137 virtual float GetCenterX() const;
138 virtual float GetCenterY() const;
139
140 float GetPointX(const std::string & point) const;
141 float GetPointY(const std::string & point) const;
142
143 void UpdateCurrentSprite() const;
144 const sf::Sprite & GetCurrentSFMLSprite() const;
145 const Sprite & GetCurrentSprite() const;
146
150 void StopAnimation() { animationStopped = true; };
152 void PlayAnimation() { animationStopped = false; };
153 bool IsAnimationStopped() const { return animationStopped; }
154 bool AnimationEnded() const;
155 unsigned int GetAnimationCount() const;
156
157 inline unsigned int GetCurrentAnimation() const { return currentAnimation; }
158 bool SetCurrentAnimation(unsigned int nb);
160
161 bool CursorOnObject( RuntimeScene & scene, bool accurate );
162
163 virtual bool SetAngle(float newAngle);
164 virtual float GetAngle() const;
165
166 bool SetDirection(float nb);
167 inline unsigned int GetCurrentDirection() const { return currentDirection; }
168
172 float GetCurrentDirectionOrAngle() const;
173
174 bool SetSprite(unsigned int nb);
175 inline unsigned int GetSpriteNb() const { return currentSprite; }
176
177 void SetOpacity(float val);
178 inline float GetOpacity() const {return opacity;};
179
180 inline void SetBlendMode(unsigned int blendMode_) { blendMode = blendMode_; };
181 inline unsigned int GetBlendMode() const {return blendMode;};
182
183 inline void SetScaleX(float val) { if ( val > 0 ) scaleX = val; needUpdateCurrentSprite = true; };
184 inline float GetScaleX() const { return scaleX; };
185 inline void SetScaleY(float val) { if ( val > 0 ) scaleY = val; needUpdateCurrentSprite = true; };
186 inline float GetScaleY() const { return scaleY; };
187
188 void SetColor(unsigned int r,unsigned int v,unsigned int b);
189 unsigned int GetColorR() const;
190 unsigned int GetColorV() const;
191 unsigned int GetColorB() const;
192
193 virtual std::vector<Polygon2d> GetHitBoxes() const;
194
195 void FlipX(bool flip = true);
196 void FlipY(bool flip = true);
197 bool IsFlippedX() const { return isFlippedX; };
198 bool IsFlippedY() const { return isFlippedY; };
199
200 void TurnTowardPosition(float Xposition, float Yposition);
201 void TurnTowardObject( RuntimeObject * object );
202
206 void ChangeScale(const std::string & operatorStr, double newValue);
207
211 void SetColor(const std::string & colorStr);
212
213 void CopyImageOnImageOfCurrentSprite(RuntimeScene & scene, const std::string & imageName, float xPosition, float yPosition, bool useTransparency);
214 void MakeColorTransparent( const std::string & colorStr );
215
216 private:
217
218 //Animations, Directions et numéro de sprite actuel
219 unsigned int currentAnimation;
220 unsigned int currentDirection;
221 float currentAngle;
222 unsigned int currentSprite;
223 bool animationStopped;
224 float timeElapsedOnCurrentSprite;
225
226 mutable Sprite * ptrToCurrentSprite; //Ptr to the current sprite
227 mutable bool needUpdateCurrentSprite;
228
229 mutable std::vector < AnimationProxy > animations;
230 mutable unsigned int cacheAnimationsSize;
231 mutable bool cacheAnimationSizeNeedUpdate;
232
233 float opacity;
234 unsigned int blendMode;
235 bool isFlippedX;
236 bool isFlippedY;
237
238 float scaleX;
239 float scaleY;
240
241 //Color filter
242 unsigned int colorR;
243 unsigned int colorV;
244 unsigned int colorB;
245
246 //Null objects if need to return a bad object.
247 static sf::Sprite badSprite;
248 static Sprite badSpriteDatas;
249 static Animation badAnimation;
250 };
251
252
253 GD_API void DestroySpriteObject(gd::Object * object);
254 GD_API gd::Object * CreateSpriteObject(std::string name);
255 GD_API void DestroyRuntimeSpriteObject(RuntimeObject * object);
256 GD_API RuntimeObject * CreateRuntimeSpriteObject(RuntimeScene & scene, const gd::Object & object);
257
258 #endif // SPRITEOBJECT_H
259