AppEasy Core SDK  1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
CzSpriteManager.h
Go to the documentation of this file.
00001 // 
00002 //
00003 // AppEasy SDK - Cross Platform Multi-purpose Game and App Engine
00004 //
00005 // Developed by Matthew Hopwood of Pocketeers Limited - www.pocketeers.co.uk
00006 //
00007 // For updates, tutorials and more details check out www.appeasymobile.com
00008 //
00009 // This code is provided free of charge and without any warranty whatsoever. You must ensure that this whole notice is present in all files and derivatives, so the reader knows its origin.
00010 // If you use this SDK in your product then please ensure that you credit AppEasy's usage appropriately. Please see www.appeasymobile.com for licensing details and support
00011 //
00012 //
00013 
00014 #if !defined(_CCZ_SPRITE_MANAGER_H_)
00015 #define _CCZ_SPRITE_MANAGER_H_
00016 
00017 #include "CzSprite.h"
00018 
00019 class CzSpriteManager;
00020 
00021 //
00022 //
00023 // CzSpriteManager - A sprite manager 
00024 //
00025 // The sprite manager managers a collection of sprites, including drawing, tracking and clean up
00026 // The sprite manager also carries its own visual transform that will be applied to all of its children, allowing the user to apply rotation, scaling ans translation to all child sprites
00027 //
00028 //
00029 class CzSpriteManager
00030 {
00031 public:
00032     // Provide public access to iteration of the sprite list
00033     typedef CzList<CzSprite*>::iterator Iterator;
00034     Iterator        begin() { return Sprites.begin(); }
00035     Iterator        end()   { return Sprites.end(); }
00036 
00037     // Properties
00038 protected:
00039     CzMatrix3               Transform;              // Transform
00040     CzMatrix3               TransformNoCamera;      // Transform without camera
00041     CzList<CzSprite*>       Sprites;                // Our list of sprites
00042     CzSlotArray<CzSprite*>* Layers;                 // Visible layers used in depth sorting
00043     bool                    Batching;               // Enable sprite batching
00044     CzVec2                  COP;                    // Centre of projection
00045     CzVec2                  ScreenCentre;           // Screen centre
00046     CzVec4                  ScreenClipRect;         // Screen clipping rectangle
00047     CzVec4                  ClipRect;               // Clipping rectangle
00048 public:
00049     void                addSprite(CzSprite* sprite);
00050     void                removeSprite(CzSprite* sprite, bool delete_sprites = true);
00051     void                setTransform(const CzMatrix3& transform)    { Transform = transform; DirtyChildTransforms(); }
00052     CzMatrix3&          getTransform()                          { return Transform; }
00053     void                setTransformNoCamera(const CzMatrix3& transform)    { TransformNoCamera = transform; DirtyChildTransforms(); }
00054     CzMatrix3&          getTransformNoCamera()                  { return TransformNoCamera; }
00055     void                setBatching(bool batching)              { Batching = batching; }
00056     bool                getBatching() const                     { return Batching; }
00057     void                setCOP(float x, float y)                { COP.x = x; COP.y = y; }
00058     CzVec2              getCOP() const                          { return COP; }
00059     void                setScreenCentre(float x, float y)       { ScreenCentre.x = x; ScreenCentre.y = y; }
00060     CzVec2              getScreenCentre() const                 { return ScreenCentre; }
00061     void                setScreenClipRect(CzVec4& rect)         { ScreenClipRect = rect; }
00062     void                setScreenClipRect(float x, float y, float w, float h)   { ScreenClipRect.x = x; ScreenClipRect.y = y; ScreenClipRect.z = w; ScreenClipRect.w = h; }
00063     CzVec4              getScreenClipRect() const               { return ScreenClipRect; }
00064     void                setClipRect(CzVec4& rect)               { ClipRect = rect; }
00065     void                setClipRect(float x, float y, float w, float h) { ClipRect.x = x; ClipRect.y = y; ClipRect.z = w; ClipRect.w = h; }
00066     CzVec4              getClipRect() const                     { return ClipRect; }
00067     // Properties End
00068 
00069 protected:
00070     void                DirtyChildTransforms();     // Dirties all child transforms to force them to update
00071     int                 MaxLayers;                  // Maximum layers
00072     void                ClearLayers();              // Clears all visible layers ready for next frame
00073 
00074 public:
00075     CzSpriteManager() : MaxLayers(0), Batching(true)
00076     {
00077     }
00078     virtual ~CzSpriteManager() { Release(); }
00079 
00080     void            Init(int max_layers = 10);
00081     void            Draw();
00082     void            Release(bool delete_sprites = true);
00083 };
00084 
00085 
00086 
00087 #endif // _CCZ_SPRITE_MANAGER_H_