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
CzSprite Class Reference

A sprite is the visual representation of an on screen game object. More...

#include <CzSprite.h>

Inheritance diagram for CzSprite:
CzBitmapSprite CzDummySprite CzTextSprite CzBitmapPoly CzBitmapSprite9

List of all members.

Public Types

enum  eType {
  ST_None, ST_Image, ST_Text, ST_Dummy,
  ST_9Patch, ST_Poly
}
 Values that represent the type of sprite to render. More...
enum  eAnchor { Centre, TopLeft }
typedef CzList< CzSprite * >
::iterator 
Iterator

Public Member Functions

Iterator begin ()
Iterator end ()
void setActor (CzActor *owner)
void setParent (CzSprite *parent)
CzSpritegetParent ()
void addChild (CzSprite *sprite)
 Adds a child sprite to the sprites child list.
void removeChild (CzSprite *sprite, bool delete_sprites=true)
 Removes a child sprite from teh child list and optionally destroys it.
void setSpriteType (eType type)
eType getSpriteType () const
void setManager (CzSpriteManager *manager)
CzSpriteManagergetManager ()
void setDestSize (int width, int height)
void setDepth (float depth)
float getDestWidth () const
float getDestHeight () const
CzVec2 getDestSize () const
float getDepth () const
void setPosAngScale (float x, float y, float angle, float scale)
void setPosAngScale (float x, float y, float angle, float scale_x, float scale_y)
void setPosition (float x, float y)
CzVec2 getPosition () const
void setOrigin (float x, float y)
CzVec2 getOrigin () const
void setSkew (float x1, float x2, float y1, float y2)
CzVec4 getSkew () const
void setAngle (float angle)
float getAngle () const
void setScale (float scale)
void setScale (float scale_x, float scale_y)
float getScale () const
float getScaleX () const
float getScaleY () const
virtual void setColour (const CzColour &colour, bool use_parent=false)
CzColour getColour () const
int getOpacity () const
void setVisible (bool show)
bool isVisible () const
void setFilter (bool enable)
bool isFilter () const
bool isVisibleWithParents () const
 Checks up the sprite hierarchy to see if the sprite and its parents are visible.
void forceTransformDirty ()
void setPooled (bool pooled)
bool isPooled () const
void setInUse (bool in_use)
bool isInUse () const
void setLayer (int layer)
int getLayer () const
CzMatrix3getTransform ()
void setLinkedTo (CzSprite *sprite)
 Changes sprite linkage.
CzSpritegetLinkedTo ()
float getAccumDepth () const
bool isTransformDirty () const
IzBrushgetBrush ()
int getVertexCount () const
void setClipRect (CzVec4 &rc)
 Sets the sprites clip rectangle.
CzVec4 getClipRect () const
CzVec4 getScreenClipRect () const
void setBeforeChildren (bool before)
bool getBeforeChildren () const
CzMatrix3getFinalTransform ()
bool affectsClip () const
CzVec4 FindFirstClipRect ()
 Searches up the sprite hierarchy for the first clip rectangle.
CzVec4 FindFirstScreenClipRect ()
 Searches up the sprite hierarchy for the first valid screen clip rectangle.
CzVec4 FindFirstScreenClipRect2 ()
 Searches up the sprite hierarchy for the first valid screen clip rectangle.
virtual bool isClipped ()
 Query if this sprite is clipped.
CzVec2getScreenV ()
void setAlphaMode (eCzAlphaMode mode)
eCzAlphaMode getAlphaMode () const
void setOrphan (bool enable)
bool getOrphan () const
void setIgnoreCamera (bool enable)
bool getIgnoreCamera () const
void setTiled (bool tiled)
bool isTiled () const
CzRenderPrimgetPrim ()
CzRenderMaterialgetMaterial ()
eAnchor getAnchor () const
void setAnchor (eAnchor anchor)
CzGeometrygetGemoetry ()
virtual void setGeometry (CzGeometry *geom)
 Sets the sprites geometry. The geometry defines what shape will be rendered by the sprite.
 CzSprite ()
virtual ~CzSprite ()
virtual void Init (int vertex_count=4)
 Initialises the sprite.
virtual bool Update ()
 Updates the sprite and any child sprites.
virtual void Draw ()=0
virtual void DrawChildren ()
 Draw the sprites child sprites.
virtual bool HitTest (float x, float y)
 Tests if an x.y point is within the sprites boundaries.
virtual bool HitTestNoClip (float x, float y)
 Tests if an x.y point is within the sprites boundaries.
virtual bool isOutsideFocusRange (float x, float y, float scale=1.0f)
 Tests to see if the supplied point is outside a specific distance.
virtual CzVec2 TransformPoint (float x, float y)
 Transform supplied point by current sprite transform.
virtual CzVec2 TransformPointToScreen (float x, float y)
 Transform supplied point by current sprite final transform (to screen coordinates).
void BringToFront ()
 Bring sprite to front of other sprites.
virtual void RebuildTransformNow ()
 Rebuild the sprites transform immediately (if dirty).
bool isClippedByManager (uint16 *indices=NULL, int count=4)
 Checks to see if the sprite is clipped by the sprite manager.
virtual bool SimpleTestOverlap (CzSprite *other)
 A simple method to test for overlapping sprites.
virtual bool TestOverlap (CzSprite *other, int i1, int i2, int i3)
 Tests if the supplied triangular area of the sprite overlaps this sprite.
virtual bool TestOverlap (CzSprite *other)
 Tests for the overlapping of two sprites.

Static Public Attributes

static uint16 SpriteIndices [] = { 0, 3, 1, 2 }

Protected Member Functions

void TransformClipRect ()
 Transforms the local clipping rect to screen coords.
virtual void RebuildTransform ()
 Rebuilds the display transform.
virtual void BuildFinalTransform ()
 Buiolds the final transform.
virtual void TransformVertices ()
 Builds a list of transformed vertices.
void UpdateClipping ()
 Updates the gobal clipper to the sprites currenmt clipping rect.

Protected Attributes

CzActorActor
 The actor that this sprite is attached to.
CzGeometryGeometry
 Geometry used to display the sprite.
CzSpriteParent
 Parent sprite.
CzList< CzSprite * > Children
 List of children sprites.
eType SpriteType
 Type of sprite.
CzSpriteManagerManager
 Parent sprite manager.
float Width
float Height
 Destination width and height (used to represent the visible extents of the sprite on screen)
float Depth
 Depth.
CzMatrix3 Transform
 Transform.
CzVec2 Position
 Position of the sprite.
CzVec2 Origin
 Origin of sprite (0, 0 is sprites centre)
CzVec4 Skew
 4 vertex skew offsets (3 bit fixed)
float Angle
 Rotation of sprite (degrees)
float ScaleX
 X axis scale of sprite.
float ScaleY
 X axis scale of sprite.
CzColour Colour
 Colour of sprite.
bool Visible
 Sprites visible state.
bool Pooled
 Tells system if we belong to a sprite pool or not.
bool InUse
 Used in a memory pooling system to mark this sprite as in use.
bool BeforeChildren
 When true th parent sprite will be drawn before all children otherwise after.
int Layer
 Depth layer.
CzSpriteLinkedTo
 When a sprite is linked to another it takes on that sprites transform etc..
IzBrushBrush
 Current brush assigned to this sprite.
CzVec4 ClipRect
 Local clipping rect used to clip this sprites children.
bool Orphan
 When set to true sprites are orphaned outside the usual parent / child hierarchy and layered as independent objects.
bool IgnoreCamera
 When set to true sprite ignores camera transform.
eAnchor Anchor
 Position the sprite is anchored around.
bool ChildChangeClip
 Set to true if child changes clip rect.
CzMatrix3 FinalTransform
 Final transform.
bool TransformDirty
 Dirty when transform changed.
CzRenderPrimPrim
 2D renderer primitive used to render this sprite
CzRenderMaterialMaterial
 Material used to render this sprite.
float AccumDepth
 Accumulated depth.
CzVec4 ScreenClipRect
 Transformed screen clipping rect for this sprite.

Detailed Description

A sprite is the visual representation of an on screen game object.

Can be thought of as an interface rather than a concrete class as other sprite types are created from this.


Member Typedef Documentation

typedef CzList<CzSprite*>::iterator CzSprite::Iterator

Member Enumeration Documentation

Enumerator:
Centre 

Sprite will be anchored around its centre.

TopLeft 

Sprite will be anchored around its top left corner.

Values that represent the type of sprite to render.

Enumerator:
ST_None 

Invalid type.

ST_Image 

Renders as an image sprite.

ST_Text 

Renders as a text sprite.

ST_Dummy 

A dummy sprite has no visible component and is only meant to provide invisible transforms.

ST_9Patch 

Renders as a 9-patch image sprite.

ST_Poly 

Renders as a poygon image sprite.


Constructor & Destructor Documentation

CzSprite::CzSprite ( ) [inline]
CzSprite::~CzSprite ( ) [virtual]

Member Function Documentation

void CzSprite::addChild ( CzSprite sprite)

Adds a child sprite to the sprites child list.

Parameters:
[in,out]spriteIf non-null, the sprite.
bool CzSprite::affectsClip ( ) const [inline]
Iterator CzSprite::begin ( ) [inline]

Bring sprite to front of other sprites.

If sprite is assigned to a manager then it will be ulinked and relinked back into the manager so that it will be drawn last. If the sprite is assigned as a child of another sprite then it will be ulinked and relinked back into the sprites child list so it will be the last drawn sprite in its parents sprite list.

void CzSprite::BuildFinalTransform ( ) [protected, virtual]

Buiolds the final transform.

Builds the sprites final transform.

The sprites local transform is combined with the sprite managers transform to create a final transform that transforms the sprite from its local sprite coordinates to screen coordinates.

Note that if the sprite has depth then basic perspective projection will be applied to the sprites position.

virtual void CzSprite::Draw ( ) [pure virtual]
void CzSprite::DrawChildren ( ) [virtual]

Draw the sprites child sprites.

Iterator CzSprite::end ( ) [inline]

Searches up the sprite hierarchy for the first clip rectangle.

Returns:
The found clip rectangle.

Searches up the sprite hierarchy for the first valid screen clip rectangle.

This method does not check the current sprites screen clip rect.

Returns:
The found screen clip rectangle.

Searches up the sprite hierarchy for the first valid screen clip rectangle.

This method will check the current sprites screen clip rect

Returns:
The found screen clip rectangle 2.
void CzSprite::forceTransformDirty ( ) [inline]
float CzSprite::getAccumDepth ( ) const [inline]
eAnchor CzSprite::getAnchor ( ) const [inline]
float CzSprite::getAngle ( ) const [inline]
bool CzSprite::getBeforeChildren ( ) const [inline]
IzBrush* CzSprite::getBrush ( ) [inline]
CzVec4 CzSprite::getClipRect ( ) const [inline]
CzColour CzSprite::getColour ( ) const [inline]
float CzSprite::getDepth ( ) const [inline]
float CzSprite::getDestHeight ( ) const [inline]
CzVec2 CzSprite::getDestSize ( ) const [inline]
float CzSprite::getDestWidth ( ) const [inline]
bool CzSprite::getIgnoreCamera ( ) const [inline]
int CzSprite::getLayer ( ) const [inline]
int CzSprite::getOpacity ( ) const [inline]
CzVec2 CzSprite::getOrigin ( ) const [inline]
bool CzSprite::getOrphan ( ) const [inline]
CzVec2 CzSprite::getPosition ( ) const [inline]
float CzSprite::getScale ( ) const [inline]
float CzSprite::getScaleX ( ) const [inline]
float CzSprite::getScaleY ( ) const [inline]
CzVec4 CzSprite::getScreenClipRect ( ) const [inline]
CzVec4 CzSprite::getSkew ( ) const [inline]
eType CzSprite::getSpriteType ( ) const [inline]
int CzSprite::getVertexCount ( ) const [inline]
bool CzSprite::HitTest ( float  x,
float  y 
) [virtual]

Tests if an x.y point is within the sprites boundaries.

Note that this method will automatically fail if the x,y point is outside the sprite managers clipping window rect.

Parameters:
xThe x coordinate.
yThe y coordinate.
Returns:
true if the test passes, false if the test fails.

Reimplemented in CzBitmapSprite9, and CzBitmapPoly.

bool CzSprite::HitTestNoClip ( float  x,
float  y 
) [virtual]

Tests if an x.y point is within the sprites boundaries.

This method does not take into accuont any cliping rects that are assigned to the sprites manager.

Parameters:
xThe x coordinate.
yThe y coordinate.
Returns:
true if the test passes, false if the test fails.

Reimplemented in CzBitmapSprite9, and CzBitmapPoly.

void CzSprite::Init ( int  vertex_count = 4) [virtual]

Initialises the sprite.

Parameters:
vertex_countNumber of vertices that the sprite is made up from.

Reimplemented in CzBitmapSprite, CzTextSprite, and CzBitmapSprite9.

bool CzSprite::isClipped ( ) [virtual]

Query if this sprite is clipped.

Returns:
true if clipped, false if not.

Reimplemented in CzBitmapSprite9, and CzBitmapPoly.

bool CzSprite::isClippedByManager ( uint16 *  indices = NULL,
int  count = 4 
)

Checks to see if the sprite is clipped by the sprite manager.

Utility method that checks the sprites current transformed vertices and the order defined by the supplied vertex indices list to see if they are fully clipped.

Parameters:
[in]indicesIf non-null, the sprites vertex indices.
countNumber of vertices.
Returns:
true if clipped by manager, false if not.
bool CzSprite::isFilter ( ) const [inline]
bool CzSprite::isInUse ( ) const [inline]
bool CzSprite::isOutsideFocusRange ( float  x,
float  y,
float  scale = 1.0f 
) [virtual]

Tests to see if the supplied point is outside a specific distance.

The focus range is the distance that a point has to move to to be declared as no longer having touch focus. The default focus range is calculated as the longest distance between each end of the sprite. The supplied scale value can be used to increase the focus range. For example a scale value of 2.0 will increase the focus range to double the size of the sprites visible dimensions.

Parameters:
xThe x coordinate.
yThe y coordinate.
scaleThe amount to scale the focus range.
Returns:
true if outside focus range, false if not.

Reimplemented in CzBitmapSprite9.

bool CzSprite::isPooled ( ) const [inline]
bool CzSprite::isTiled ( ) const [inline]
bool CzSprite::isTransformDirty ( ) const [inline]
bool CzSprite::isVisible ( ) const [inline]

Checks up the sprite hierarchy to see if the sprite and its parents are visible.

Returns:
true if visible and its parents are visible, false if not.
void CzSprite::RebuildTransform ( ) [protected, virtual]

Rebuilds the display transform.

Rebuilds the sprites display transform.

Reimplemented in CzTextSprite.

void CzSprite::RebuildTransformNow ( ) [virtual]

Rebuild the sprites transform immediately (if dirty).

void CzSprite::removeChild ( CzSprite sprite,
bool  delete_sprites = true 
)

Removes a child sprite from teh child list and optionally destroys it.

Parameters:
[in]spriteIf non-null, the sprite.
delete_spritestrue to delete the sprites.
void CzSprite::setActor ( CzActor owner) [inline]
void CzSprite::setAlphaMode ( eCzAlphaMode  mode) [inline]
void CzSprite::setAnchor ( eAnchor  anchor) [inline]
void CzSprite::setAngle ( float  angle) [inline]
void CzSprite::setBeforeChildren ( bool  before) [inline]
void CzSprite::setClipRect ( CzVec4 rc)

Sets the sprites clip rectangle.

Parameters:
[in,out]rcThe clip rectangle.
virtual void CzSprite::setColour ( const CzColour colour,
bool  use_parent = false 
) [inline, virtual]

Reimplemented in CzBitmapSprite.

void CzSprite::setDepth ( float  depth) [inline]
void CzSprite::setDestSize ( int  width,
int  height 
) [inline]
void CzSprite::setFilter ( bool  enable) [inline]
void CzSprite::setGeometry ( CzGeometry geom) [virtual]

Sets the sprites geometry. The geometry defines what shape will be rendered by the sprite.

Parameters:
[in]geomIf non-null, the geometry.

Reimplemented in CzBitmapSprite.

void CzSprite::setIgnoreCamera ( bool  enable) [inline]
void CzSprite::setInUse ( bool  in_use) [inline]
void CzSprite::setLayer ( int  layer) [inline]
void CzSprite::setLinkedTo ( CzSprite sprite)

Changes sprite linkage.

Sprites by default are placed in the sprite manager. When a sprite is linked to another sprite it is removed from the sprite manager and added to that sprites child list unless it is an orphan sprite.

Parameters:
[in,out]spriteIf non-null, the sprite.
void CzSprite::setManager ( CzSpriteManager manager) [inline]
void CzSprite::setOrigin ( float  x,
float  y 
) [inline]
void CzSprite::setOrphan ( bool  enable) [inline]
void CzSprite::setParent ( CzSprite parent) [inline]
void CzSprite::setPooled ( bool  pooled) [inline]
void CzSprite::setPosAngScale ( float  x,
float  y,
float  angle,
float  scale 
) [inline]
void CzSprite::setPosAngScale ( float  x,
float  y,
float  angle,
float  scale_x,
float  scale_y 
) [inline]
void CzSprite::setPosition ( float  x,
float  y 
) [inline]
void CzSprite::setScale ( float  scale) [inline]
void CzSprite::setScale ( float  scale_x,
float  scale_y 
) [inline]
void CzSprite::setSkew ( float  x1,
float  x2,
float  y1,
float  y2 
) [inline]
void CzSprite::setSpriteType ( eType  type) [inline]
void CzSprite::setTiled ( bool  tiled) [inline]
void CzSprite::setVisible ( bool  show) [inline]
bool CzSprite::SimpleTestOverlap ( CzSprite other) [virtual]

A simple method to test for overlapping sprites.

Note that this nethod does not take into account rotation.

Parameters:
[in]otherIf non-null, the other sprite.
Returns:
true if overlap, false if no overlap.

Reimplemented in CzBitmapSprite9, and CzBitmapPoly.

bool CzSprite::TestOverlap ( CzSprite other,
int  i1,
int  i2,
int  i3 
) [virtual]

Tests if the supplied triangular area of the sprite overlaps this sprite.

Using 3 vertices at the supplied indices i1, i2, i3 of the supplied sprites transformed vertices to see if the overlap this sprites vertices.

Note that this method can also test against 16 vertex patch sprites

Parameters:
[in]otherIf non-null, the other.
i1First vertex index.
i2Second vertex index.
i3Third vertex index.
Returns:
true if overlap, false if no overlap.

Reimplemented in CzBitmapSprite9.

bool CzSprite::TestOverlap ( CzSprite other) [virtual]

Tests for the overlapping of two sprites.

This method takes into account rotation of both sprites. However, it will revert to a simple method of overlap testing if both sprites are not rotated.

Parameters:
[in,out]otherIf non-null, the other sprite.
Returns:
true if overlap, false if no overlap.

Reimplemented in CzBitmapSprite9, and CzBitmapPoly.

void CzSprite::TransformClipRect ( ) [protected]

Transforms the local clipping rect to screen coords.

Transform the sprites clipping rectangle.

CzVec2 CzSprite::TransformPoint ( float  x,
float  y 
) [virtual]

Transform supplied point by current sprite transform.

Parameters:
xThe x coordinate.
yThe y coordinate.
Returns:
Transformed point.
CzVec2 CzSprite::TransformPointToScreen ( float  x,
float  y 
) [virtual]

Transform supplied point by current sprite final transform (to screen coordinates).

Parameters:
xThe x coordinate.
yThe y coordinate.
Returns:
Transformed point in screen coordinates.
void CzSprite::TransformVertices ( ) [protected, virtual]

Builds a list of transformed vertices.

Transform sprites vertices by current sprite transform.

Reimplemented in CzTextSprite, CzBitmapSprite9, and CzBitmapPoly.

bool CzSprite::Update ( ) [virtual]

Updates the sprite and any child sprites.

Returns:
true if visible, false if not.
void CzSprite::UpdateClipping ( ) [protected]

Updates the gobal clipper to the sprites currenmt clipping rect.


Member Data Documentation

float CzSprite::AccumDepth [protected]

Accumulated depth.

CzActor* CzSprite::Actor [protected]

The actor that this sprite is attached to.

Position the sprite is anchored around.

float CzSprite::Angle [protected]

Rotation of sprite (degrees)

bool CzSprite::BeforeChildren [protected]

When true th parent sprite will be drawn before all children otherwise after.

IzBrush* CzSprite::Brush [protected]

Current brush assigned to this sprite.

bool CzSprite::ChildChangeClip [protected]

Set to true if child changes clip rect.

List of children sprites.

Local clipping rect used to clip this sprites children.

Colour of sprite.

float CzSprite::Depth [protected]

Depth.

Final transform.

Geometry used to display the sprite.

Reimplemented in CzBitmapPoly.

float CzSprite::Height [protected]

Destination width and height (used to represent the visible extents of the sprite on screen)

bool CzSprite::IgnoreCamera [protected]

When set to true sprite ignores camera transform.

bool CzSprite::InUse [protected]

Used in a memory pooling system to mark this sprite as in use.

int CzSprite::Layer [protected]

Depth layer.

When a sprite is linked to another it takes on that sprites transform etc..

Parent sprite manager.

Material used to render this sprite.

CzVec2 CzSprite::Origin [protected]

Origin of sprite (0, 0 is sprites centre)

bool CzSprite::Orphan [protected]

When set to true sprites are orphaned outside the usual parent / child hierarchy and layered as independent objects.

CzSprite* CzSprite::Parent [protected]

Parent sprite.

bool CzSprite::Pooled [protected]

Tells system if we belong to a sprite pool or not.

Position of the sprite.

2D renderer primitive used to render this sprite

float CzSprite::ScaleX [protected]

X axis scale of sprite.

float CzSprite::ScaleY [protected]

X axis scale of sprite.

Transformed screen clipping rect for this sprite.

CzVec4 CzSprite::Skew [protected]

4 vertex skew offsets (3 bit fixed)

uint16 CzSprite::SpriteIndices = { 0, 3, 1, 2 } [static]

Type of sprite.

Transform.

bool CzSprite::TransformDirty [protected]

Dirty when transform changed.

bool CzSprite::Visible [protected]

Sprites visible state.

float CzSprite::Width [protected]

The documentation for this class was generated from the following files: