CUGL 1.3
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::MoveTo Class Reference

#include <CUMoveAction.h>

Inheritance diagram for cugl::MoveTo:
cugl::Action

Public Member Functions

 MoveTo ()
 
 ~MoveTo ()
 
void dispose ()
 
bool init ()
 
bool init (const Vec2 &target)
 
bool init (const Vec2 &target, float time)
 
const Vec2getTarget () const
 
void setTarget (const Vec2 &target)
 
virtual std::shared_ptr< Actionclone () override
 
virtual void load (const std::shared_ptr< Node > &target, Uint64 *state) override
 
virtual void update (const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
 
virtual std::string toString (bool verbose=false) const override
 
- Public Member Functions inherited from cugl::Action
 Action ()
 
 ~Action ()
 
float getDuration () const
 
void setDuration (float time)
 
 operator std::string () const
 

Static Public Member Functions

static std::shared_ptr< MoveToalloc ()
 
static std::shared_ptr< MoveToalloc (const Vec2 &target)
 
static std::shared_ptr< MoveToalloc (const Vec2 &target, float time)
 

Protected Attributes

Vec2 _target
 
- Protected Attributes inherited from cugl::Action
float _duration
 

Detailed Description

This action represents a movement to a given position

An action contains only the definition of the transformation; it does not contain any attribute of the target. Hence, an action it can be reapplied to different targets.

By itself, an action does nothing. It only specifies an action that may take place. To use an action, it must be passed to the ActionManager. The manager will create an action instance and animate that instance. While an action may be reused many times, an action instance corresponds to a single animation.

Constructor & Destructor Documentation

◆ MoveTo()

cugl::MoveTo::MoveTo ( )
inline

Creates an uninitialized movement action.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.

◆ ~MoveTo()

cugl::MoveTo::~MoveTo ( )
inline

Deletes this action instance, disposing all resources

Member Function Documentation

◆ alloc() [1/3]

static std::shared_ptr<MoveTo> cugl::MoveTo::alloc ( )
inlinestatic

Returns a newly allocated, instantaneous motion towards the origin.

The target position is set to (0.0, 0.0), meaning that this action will move a node towards the origin. The animation will be instantaneous.

Returns
a newly allocated, instantaneous motion towards the origin.

◆ alloc() [2/3]

static std::shared_ptr<MoveTo> cugl::MoveTo::alloc ( const Vec2 target)
inlinestatic

Returns a newly allocated, instantaneous motion towards the given position.

The animation will be instantaneous.

Parameters
targetThe target position
Returns
a newly allocated, instantaneous motion towards the given position.

◆ alloc() [3/3]

static std::shared_ptr<MoveTo> cugl::MoveTo::alloc ( const Vec2 target,
float  time 
)
inlinestatic

Returns a newly allocated motion towards the given position.

The animation will take place over the given number of seconds.

Parameters
targetThe target position
timeThe animation duration
Returns
a newly allocated motion towards the given position.

◆ clone()

virtual std::shared_ptr<Action> cugl::MoveTo::clone ( )
overridevirtual

Returns a newly allocated copy of this Action.

Returns
a newly allocated copy of this Action.

Reimplemented from cugl::Action.

◆ dispose()

void cugl::MoveTo::dispose ( )
inline

Disposes all of the resources used by this action.

A disposed action can be safely reinitialized.

◆ getTarget()

const Vec2& cugl::MoveTo::getTarget ( ) const
inline

Returns the movement target for this action.

Changing this value for an actively animating action can have undefined effects.

Returns
the movement target for this action.

◆ init() [1/3]

bool cugl::MoveTo::init ( )
inline

Initializes an instantaneous movement towards the origin.

The target position is set to (0.0, 0.0), meaning that this action will move a node towards the origin. The animation will be instantaneous.

Returns
true if initialization was successful.

◆ init() [2/3]

bool cugl::MoveTo::init ( const Vec2 target)
inline

Initializes an instantaneous movement towards towards the given position.

The animation will be instantaneous.

Parameters
targetThe target position
Returns
true if initialization was successful.

◆ init() [3/3]

bool cugl::MoveTo::init ( const Vec2 target,
float  time 
)

Initializes a movement animation towards towards the given position.

The animation will take place over the given number of seconds.

Parameters
targetThe target position
timeThe animation duration
Returns
true if initialization was successful.

◆ load()

virtual void cugl::MoveTo::load ( const std::shared_ptr< Node > &  target,
Uint64 *  state 
)
overridevirtual

Prepares a target for action

The important state of the target is stored in the given state parameter. The semantics of this state is action-dependent.

Parameters
targetThe node to act on
stateThe relevant node state

Reimplemented from cugl::Action.

◆ setTarget()

void cugl::MoveTo::setTarget ( const Vec2 target)
inline

Sets the movement target for this action.

Changing this value for an actively animating action can have undefined effects.

Parameters
targetthe movement target for this action.

◆ toString()

virtual std::string cugl::MoveTo::toString ( bool  verbose = false) const
overridevirtual

Returns a string representation of the action for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this action for debuggging purposes.

Reimplemented from cugl::Action.

◆ update()

virtual void cugl::MoveTo::update ( const std::shared_ptr< Node > &  target,
Uint64 *  state,
float  dt 
)
overridevirtual

Executes an action on the given target node.

The important state of the target is stored in the given state parameter. The semantics of this state is action-dependent.

Parameters
targetThe node to act on
stateThe relevant node state
dtThe elapsed time to animate.

Reimplemented from cugl::Action.

Member Data Documentation

◆ _target

Vec2 cugl::MoveTo::_target
protected

The target destination for this action


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