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

A camera is generally used to display aa area of a game scene, usually tracking some actor. More...

#include <CzCamera.h>

Inheritance diagram for CzCamera:
IzXomlResource

List of all members.

Public Member Functions

CzMatrix3getTransform ()
void setPosition (float x, float y)
CzVec2 getPosition () const
void setVelocity (float x, float y)
CzVec2 getVelocity () const
void setVelocityDamping (float x, float y)
CzVec2 getVelocityDamping () const
void setFollowSpeed (float x, float y)
CzVec2 getFollowSpeed () const
void setScale (float scale)
float getScale () const
void setAngle (float angle)
float getAngle () const
void setTargetX (const char *target_name)
 Sets target x-axis actor for camera to follow on its x-axis.
void setTargetX (CzActor *target)
 Sets target x-axis actor for camera to follow on its x-axis.
void setTargetY (const char *target_name)
 Sets target y-axis actor for camera to follow on its y-axis.
void setTargetY (CzActor *target)
 Sets target y-axis actor for camera to follow on its y-axis.
void setTransformDirty (bool dirty)
bool isTransformDirty () const
void setTouchPanX (bool pan)
bool isTouchPanX () const
void setTouchPanY (bool pan)
bool isTouchPanY () const
void setIgnoreActors (bool ignore)
bool getIgnoreActors () const
virtual bool setProperty (unsigned int property_name, const CzXomlProperty &data, bool delta)
 Sets the named property of the Camera.
bool setProperty (const char *property_name, const CzString &data, bool delta)
 Sets the named property of the actor.
virtual bool setProperty (unsigned int property_name, const CzString &data, bool delta)
 Sets the named property of the actor.
bool getProperty (const char *property_name, CzXomlProperty &prop)
 Gets the named property of the actor.
virtual bool getProperty (unsigned int property_name, CzXomlProperty &prop)
 CzCamera ()
virtual ~CzCamera ()
virtual void Update (float dt)
 Updates the given dt.
int LoadFromXoml (IzXomlResource *parebt, bool load_children, CzXmlNode *node)
 Creates an instance of this class from XOML.

Static Public Member Functions

static void InitClass ()
 Initialises the class.
static void ReleaseClass ()
static bool _setName (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getName (IzXomlResource *target)
static bool _setTag (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static bool _setPosition (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getPosition (IzXomlResource *target)
static bool _setScale (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getScale (IzXomlResource *target)
static bool _setAngle (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getAngle (IzXomlResource *target)
static bool _setVelocity (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getVelocity (IzXomlResource *target)
static bool _setVelocityDamping (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getVelocityDamping (IzXomlResource *target)
static bool _setTouchPanX (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getTouchPanX (IzXomlResource *target)
static bool _setTouchPanY (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getTouchPanY (IzXomlResource *target)
static bool _setIgnoreActors (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getIgnoreActors (IzXomlResource *target)
static bool _setTargetX (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static bool _setTargetY (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static bool _setFollowSpeed (IzXomlResource *target, const CzXomlProperty &prop, bool add)
static CzXomlProperty _getFollowSpeed (IzXomlResource *target)

Protected Attributes

CzSceneScene
 Parent scene.
CzMatrix3 Transform
 The combined camera transform.
CzVec2 Position
 Position of camera within scene.
CzVec2 Velocity
 Velocity of camera.
CzVec2 VelocityDamping
 Velocity cadmping applied to slow the camera.
CzVec2 FollowSpeed
 Speed at which to follow target (1.0 is max)
float Scale
 Cameras scale.
float Angle
 Cameras angle.
bool TransformDirty
 Marks camera transform needs rebuilding.
CzActorTargetX
 Object that the camera is targeting on the x axis.
CzActorTargetY
 Object that the camera is targeting on the y axis.
unsigned int TargetXHash
 Hash of object that the camera is targeting on the x axis.
unsigned int TargetYHash
 Hash of object that the camera is targeting on the y axis.
bool TouchPanX
 If true then the camera will pan along the x-axis with the users touch.
bool TouchPanY
 If true then the camera will pan along the y-axis with the users touch.
bool IgnoreActors
 if an actor is currently focused then it will usually prevent touch panning, this will disable that

Static Protected Attributes

static CzXomlClassDefCameraClassDef = NULL

Detailed Description

A camera is generally used to display aa area of a game scene, usually tracking some actor.

A camera is a view into the scene from a specific position, angle and scale. In order to move, rotate and scale a scene a camera should be created and attached to it. To create a camera you use the Camera XOML tag:

XOML Example:
<!-- Create a camera -->
<Camera Name="Camera1" />

To attach the camera to the scene we add the Camera attribute to the scene definition:

<Scene Name="Scene1" Current="true" Camera="Camera1">

When we move, scale or rotate a scene we are actually modifying the camera view within the scene. When we move the camera objects tend to move in the opposite direction, for example moving the camera left moves the scene actors to the right. If you think about how a real camera works, when you move the camera in one direction the view seen by the camera moves in the opposite direction.

Its possible to create a number of different cameras and switch between them to offer different views into the scene.

Cameras offer a great out of the box feature called touch panning, which enables the user to pan the camera around a scene on the x and y axis by dragging their finger around the scene. Take a look at the ScenePanning example for an example showing how to use touch panning.

Lets take a look at what properties the Camera tag supports:

  • Name (string) - Cameras resource name
    • Position (x, y) - Start position of the camera
    • Angle (degrees) - Rotation of the camera
    • Scale (scale factor) - Scale of the camera (can be used for zoom effects)
    • TouchPanX / TouchPanY (boolean) - Setting true causes the camera to move around when the user drags their finger on the screen using velocity obtained from the speed of the users drag. Separate X and Y axis panning can be enabled / disabled.
    • VelocityDamping (x, y) - Amount of damping to apply to the cameras velocity (x, y) each frame. This value when set to a value of less than 1.0, 1.0 will cause the camera to slow down over time.
    • IgnoreActors (boolean) - When set to true and touch panel is enabled, dragging a finger over an actor will still be classed as a touch pan drag. This option basically allows the user to touch pan the scene regardless of what the user touches on the screen.
    • TargetX (actor name, write-only) – An actor that the camera will be used to track its x-axis position
    • TargetY (actor name, write-only) – An actor that the camera will be used to track its y-axis position
    • FollowSpeed (x, y) – The speed at which the camera should track the specified actor(s). Higher values will catch the camera up to the actors target position faster
    • Tag (string) - Group tag

Some of these properties can be modified via the scene such as Position, Angle and Scale as changes to these properties go straight to the attached camera. You can set all properties for a camera via LUA using the camera.set() function.


Constructor & Destructor Documentation

CzCamera::CzCamera ( ) [inline]
virtual CzCamera::~CzCamera ( ) [inline, virtual]

Member Function Documentation

bool CzCamera::_setAngle ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setFollowSpeed ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setIgnoreActors ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setName ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setPosition ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setScale ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setTag ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setTargetX ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setTargetY ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setTouchPanX ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setTouchPanY ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setVelocity ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
bool CzCamera::_setVelocityDamping ( IzXomlResource target,
const CzXomlProperty prop,
bool  add 
) [static]
float CzCamera::getAngle ( ) const [inline]
CzVec2 CzCamera::getFollowSpeed ( ) const [inline]
bool CzCamera::getIgnoreActors ( ) const [inline]
CzVec2 CzCamera::getPosition ( ) const [inline]
bool CzCamera::getProperty ( const char *  property_name,
CzXomlProperty prop 
)

Gets the named property of the actor.

Returns the named property of the actor. The properties value is returned in a CzXomlProperty which is a structure that contains a union of all possible property types.

Parameters:
property_nameName of the property.
[out]propThe property data.
Returns:
true if it succeeds, false if property does not exist.
bool CzCamera::getProperty ( unsigned int  property_name,
CzXomlProperty prop 
) [virtual]

Returns the named property of the actor. The properties value is returned in a CzXomlProperty which is a structure that contains a union of all possible property types.

Parameters:
property_nameName of the property as a string hash (faster searching).
[in,out]propThe property.
Returns:
true if it succeeds, false if property does not exist.
float CzCamera::getScale ( ) const [inline]
CzVec2 CzCamera::getVelocity ( ) const [inline]
void CzCamera::InitClass ( ) [static]

Initialises the class.

Sets up the classes avaiiable properties. Used by the XOML system to find, set amd get class properties.

bool CzCamera::isTouchPanX ( ) const [inline]
bool CzCamera::isTouchPanY ( ) const [inline]
bool CzCamera::isTransformDirty ( ) const [inline]
int CzCamera::LoadFromXoml ( IzXomlResource parent,
bool  load_children,
CzXmlNode node 
) [virtual]

Creates an instance of this class from XOML.

LoadFromXoml is the main method used by all classes that can be instantiated from XOML mark-up. This method creates an instance of this class from the supplied XML node structure specified by node. if parent is not NULL then the created instance will utilise the supplied parent to determine where it should live within the app. For example, if the parent is a scene then the camera will be placed in that scene. If load_chlldren is true then any child nodes contained within the node will also be loaded.

Parameters:
[in]parentIf non-null, the parent.
load_childrentrue to load child nodes.
[in]nodeIf non-null, the XOML markup node that defines this object
Returns:
nergative value for error. if 0 then processing of further XOML will stop.

Implements IzXomlResource.

void CzCamera::ReleaseClass ( ) [static]
void CzCamera::setAngle ( float  angle) [inline]
void CzCamera::setFollowSpeed ( float  x,
float  y 
) [inline]
void CzCamera::setIgnoreActors ( bool  ignore) [inline]
void CzCamera::setPosition ( float  x,
float  y 
) [inline]
bool CzCamera::setProperty ( unsigned int  property_name,
const CzXomlProperty data,
bool  delta 
) [virtual]

Sets the named property of the Camera.

Sets the named property of this Camera. The properties value supplied will be converted. If delta is set to true then the existing value of the property will be added to instead of replaced.

Parameters:
property_nameName of the property as a string hash (faster searching).
[in]dataThe property data.
deltatrue if property should be added to instead of replaced.
Returns:
true if it succeeds, false if property does not exist.
bool CzCamera::setProperty ( const char *  property_name,
const CzString data,
bool  delta 
)

Sets the named property of the actor.

Sets the named property of this actor. The properties value (data) is supplied as a string and will be converted. If delta is set to true then the existing value of the property will be added to instead of replaced.

Parameters:
property_nameName of the property.
[in]dataThe property data.
deltatrue if property should be added to instead of replaced.
Returns:
true if it succeeds, false if property does not exist.
bool CzCamera::setProperty ( unsigned int  property_name,
const CzString data,
bool  delta 
) [virtual]

Sets the named property of the actor.

Sets the named property of this actor. The properties value (data) is supplied as a string and will be converted. If delta is set to true then the existing value of the property will be added to instead of replaced.

Parameters:
property_nameName of the property as a string hash (faster searching).
[in]dataThe property data.
deltatrue if property should be added to instead of replaced.
Returns:
true if it succeeds, false if property does not exist.
void CzCamera::setScale ( float  scale) [inline]
void CzCamera::setTargetX ( const char *  target_name)

Sets target x-axis actor for camera to follow on its x-axis.

Parameters:
target_nameName of the target.
void CzCamera::setTargetX ( CzActor target)

Sets target x-axis actor for camera to follow on its x-axis.

Parameters:
[in]targetIf non-null, target for the.
void CzCamera::setTargetY ( const char *  target_name)

Sets target y-axis actor for camera to follow on its y-axis.

Parameters:
target_nameName of the target.
void CzCamera::setTargetY ( CzActor target)

Sets target y-axis actor for camera to follow on its y-axis.

Parameters:
[in]targetIf non-null, target for the.
void CzCamera::setTouchPanX ( bool  pan) [inline]
void CzCamera::setTouchPanY ( bool  pan) [inline]
void CzCamera::setTransformDirty ( bool  dirty) [inline]
void CzCamera::setVelocity ( float  x,
float  y 
) [inline]
void CzCamera::setVelocityDamping ( float  x,
float  y 
) [inline]
void CzCamera::Update ( float  dt) [virtual]

Updates the given dt.

Parameters:
dtThe number of seconds since the app was last updated

Member Data Documentation

float CzCamera::Angle [protected]

Cameras angle.

CzXomlClassDef * CzCamera::CameraClassDef = NULL [static, protected]

Speed at which to follow target (1.0 is max)

bool CzCamera::IgnoreActors [protected]

if an actor is currently focused then it will usually prevent touch panning, this will disable that

Position of camera within scene.

float CzCamera::Scale [protected]

Cameras scale.

CzScene* CzCamera::Scene [protected]

Parent scene.

CzActor* CzCamera::TargetX [protected]

Object that the camera is targeting on the x axis.

unsigned int CzCamera::TargetXHash [protected]

Hash of object that the camera is targeting on the x axis.

CzActor* CzCamera::TargetY [protected]

Object that the camera is targeting on the y axis.

unsigned int CzCamera::TargetYHash [protected]

Hash of object that the camera is targeting on the y axis.

bool CzCamera::TouchPanX [protected]

If true then the camera will pan along the x-axis with the users touch.

bool CzCamera::TouchPanY [protected]

If true then the camera will pan along the y-axis with the users touch.

The combined camera transform.

bool CzCamera::TransformDirty [protected]

Marks camera transform needs rebuilding.

Velocity of camera.

Velocity cadmping applied to slow the camera.


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