AppEasy Core SDK
1.5.0
Cross platform mobile and desktop app and game development SDK - The easy way to make apps
|
A camera is generally used to display aa area of a game scene, usually tracking some actor. More...
#include <CzCamera.h>
Public Member Functions | |
CzMatrix3 & | getTransform () |
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 | |
CzScene * | Scene |
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. | |
CzActor * | TargetX |
Object that the camera is targeting on the x axis. | |
CzActor * | TargetY |
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 CzXomlClassDef * | CameraClassDef = NULL |
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:
<!-- Create a camera --> <Camera Name="Camera1" />
To attach the camera to the scene we add the Camera attribute to the scene definition:
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:
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.
CzCamera::CzCamera | ( | ) | [inline] |
virtual CzCamera::~CzCamera | ( | ) | [inline, virtual] |
CzXomlProperty CzCamera::_getAngle | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getFollowSpeed | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getIgnoreActors | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getName | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getPosition | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getScale | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getTouchPanX | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getTouchPanY | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getVelocity | ( | IzXomlResource * | target | ) | [static] |
CzXomlProperty CzCamera::_getVelocityDamping | ( | IzXomlResource * | target | ) | [static] |
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.
property_name | Name of the property. | |
[out] | prop | The property data. |
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.
property_name | Name of the property as a string hash (faster searching). | |
[in,out] | prop | The property. |
float CzCamera::getScale | ( | ) | const [inline] |
CzMatrix3& CzCamera::getTransform | ( | ) | [inline] |
CzVec2 CzCamera::getVelocity | ( | ) | const [inline] |
CzVec2 CzCamera::getVelocityDamping | ( | ) | 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.
[in] | parent | If non-null, the parent. |
load_children | true to load child nodes. | |
[in] | node | If non-null, the XOML markup node that defines this object |
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.
property_name | Name of the property as a string hash (faster searching). | |
[in] | data | The property data. |
delta | true if property should be added to instead of replaced. |
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.
property_name | Name of the property. | |
[in] | data | The property data. |
delta | true if property should be added to instead of replaced. |
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.
property_name | Name of the property as a string hash (faster searching). | |
[in] | data | The property data. |
delta | true if property should be added to instead of replaced. |
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.
target_name | Name of the target. |
void CzCamera::setTargetX | ( | CzActor * | target | ) |
Sets target x-axis actor for camera to follow on its x-axis.
[in] | target | If 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.
target_name | Name of the target. |
void CzCamera::setTargetY | ( | CzActor * | target | ) |
Sets target y-axis actor for camera to follow on its y-axis.
[in] | target | If 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.
dt | The number of seconds since the app was last updated |
float CzCamera::Angle [protected] |
Cameras angle.
CzXomlClassDef * CzCamera::CameraClassDef = NULL [static, protected] |
CzVec2 CzCamera::FollowSpeed [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
CzVec2 CzCamera::Position [protected] |
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.
CzMatrix3 CzCamera::Transform [protected] |
The combined camera transform.
bool CzCamera::TransformDirty [protected] |
Marks camera transform needs rebuilding.
CzVec2 CzCamera::Velocity [protected] |
Velocity of camera.
CzVec2 CzCamera::VelocityDamping [protected] |
Velocity cadmping applied to slow the camera.