Angel 3.2
A 2D Game Prototyping Engine
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Actor Class Reference

Basic simulation element for Angel. More...

#include <Actor.h>

+ Inheritance diagram for Actor:

Public Member Functions

 Actor ()
 
virtual ~Actor ()
 
void SetSize (float x, float y=-1.f)
 
void SetSize (const Vector2 &newSize)
 
const Vector2GetSize () const
 
const BoundingBox GetBoundingBox () const
 
virtual void SetPosition (float x, float y)
 
virtual void SetPosition (const Vector2 &pos)
 
const Vector2GetPosition () const
 
virtual void SetRotation (float rotation)
 
const float GetRotation () const
 
void SetColor (float r, float g, float b, float a=1.0f)
 
void SetColor (const Color &color)
 
const ColorGetColor () const
 
void SetAlpha (float newAlpha)
 
const float GetAlpha () const
 
virtual void SetDrawShape (actorDrawShape drawShape)
 
const actorDrawShapeGetDrawShape () const
 
void UseDisplayList (int listIndex)
 
void MoveTo (const Vector2 &newPosition, float duration, bool smooth=false, String onCompletionMessage="")
 
void RotateTo (float newRotation, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeColorTo (const Color &newColor, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeSizeTo (const Vector2 &newSize, float duration, bool smooth=false, String onCompletionMessage="")
 
void ChangeSizeTo (float newSize, float duration, bool smooth=false, String onCompletionMessage="")
 
int GetSpriteTexture (int frame=0) const
 
bool SetSprite (const String &filename, int frame=0, GLint clampmode=GL_CLAMP, GLint filtermode=GL_LINEAR, bool optional=false)
 
void ClearSpriteInfo ()
 
void LoadSpriteFrames (const String &firstFilename, GLint clampmode=GL_CLAMP, GLint filtermode=GL_LINEAR)
 
void PlaySpriteAnimation (float delay, spriteAnimationType animType=SAT_Loop, int startFrame=-1, int endFrame=-1, const char *animName=NULL)
 
void SetSpriteFrame (int frame)
 
int GetSpriteFrame () const
 
const bool IsSpriteAnimPlaying () const
 
virtual void AnimCallback (String animName)
 
void SetUVs (const Vector2 &lowleft, const Vector2 &upright)
 
void GetUVs (Vector2 &lowleft, Vector2 &upright) const
 
const bool IsTagged (const String &tag)
 
void Tag (const String &newTag)
 
void Untag (const String &oldTag)
 
const StringSet & GetTags () const
 
const String & SetName (String newName)
 
const String & GetName () const
 
virtual void ReceiveMessage (Message *message)
 
void SetLayer (int layerIndex)
 
void SetLayer (const String &layerName)
 
virtual void Update (float dt)
 
virtual void Render ()
 
virtual void LevelUnloaded ()
 
ActorGetSelf ()
 
virtual const String GetClassName () const
 
- Public Member Functions inherited from Renderable
 Renderable ()
 
virtual ~Renderable ()
 
void Destroy ()
 
bool IsDestroyed ()
 
int GetLayer ()
 

Static Public Member Functions

static Actor *const GetNamed (const String &nameLookup)
 
static ActorCreate (const String &archetype)
 
static void SetScriptCreatedActor (Actor *a)
 

Protected Attributes

Vector2 _size
 
Vector2 _position
 
Color _color
 
float _rotation
 
float _UV [8]
 
actorDrawShape _drawShape
 
int _spriteCurrentFrame
 
int _spriteNumFrames
 
float _spriteFrameDelay
 
float _spriteCurrentFrameDelay
 
int _spriteTextureReferences [MAX_SPRITE_FRAMES]
 
spriteAnimationType _spriteAnimType
 
int _spriteAnimStartFrame
 
int _spriteAnimEndFrame
 
int _spriteAnimDirection
 
int _displayListIndex
 
StringSet _tags
 
String _name
 
String _currentAnimName
 
- Protected Attributes inherited from Renderable
bool _deleteMe
 
int _layer
 

Static Protected Attributes

static const float _squareVertices []
 
static float _circleVertices []
 
static float _circleTextureCoords []
 
static std::map< String, Actor * > _nameList
 
static Actor_scriptCreatedActor = NULL
 

Additional Inherited Members

- Protected Member Functions inherited from Renderable
virtual void PreDestroy ()
 

Detailed Description

Actor is the basic unit of simulation in Angel. It's not just an abstract base class – you can actually do a good deal of your game just using plain Actors, depending on how you want to structure your logic.

Note that you have to add the Actor to the World if you want to see it on screen.

If you want to subclass Actor, the two most important functions are Render and Update, which will get called on each Actor in the World every frame.

Definition at line 75 of file Actor.h.

Constructor & Destructor Documentation

Actor::Actor ( )

The constructor doesn't do anything special. It defaults to a square Actor with a side-length of 1.0f, no texture, white, and at the origin.

Definition at line 60 of file Actor.cpp.

Actor::~Actor ( )
virtual

The destructor ensures that the Actor has been unsubscribed from all Messages, removed from all tag lists, and purged from the list of unique names.

Definition at line 97 of file Actor.cpp.

Member Function Documentation

void Actor::SetSize ( float  x,
float  y = -1.f 
)

Set the size of this Actor.

Parameters
xHorizontal size in OpenGL units – negative numbers treated as zero
yVertical size in OpenGL units – if less than or equal to zero, assumed to be equal to x

Definition at line 326 of file Actor.cpp.

void Actor::SetSize ( const Vector2 newSize)

Set the size of this Actor.

Parameters
newSizeDesired size of Actor in OpenGL units. If either dimension is negative, it's clamped to zero.

Definition at line 340 of file Actor.cpp.

const Vector2 & Actor::GetSize ( ) const

Return the size of this Actor.

Returns
Actor's size as a Vector2

Definition at line 353 of file Actor.cpp.

const BoundingBox Actor::GetBoundingBox ( ) const

Return the BoundingBox for this Actor.

Returns
Actor's bounding box

Definition at line 358 of file Actor.cpp.

void Actor::SetPosition ( float  x,
float  y 
)
virtual

Set the position of the Actor in world coordinates.

Parameters
xX-coordinate in OpenGL units
yY-coordinate in OpenGL units

Reimplemented in PhysicsActor, Camera, and TextActor.

Definition at line 366 of file Actor.cpp.

void Actor::SetPosition ( const Vector2 pos)
virtual

Set the position of the Actor in world coordinates.

Parameters
posDesired X and Y coordinates wrapped up into a Vector2

Reimplemented in PhysicsActor, Camera, and TextActor.

Definition at line 372 of file Actor.cpp.

const Vector2 & Actor::GetPosition ( ) const

Return the position of this Actor.

Returns
Actor's position as a Vector2

Definition at line 377 of file Actor.cpp.

void Actor::SetRotation ( float  rotation)
virtual

Sets the rotation of the Actor. Positive rotations are counter-clockwise.

Parameters
rotationDesired rotation in degrees

Reimplemented in PhysicsActor, Camera, and TextActor.

Definition at line 382 of file Actor.cpp.

const float Actor::GetRotation ( ) const

Return the rotation of this Actor.

Returns
Actor's rotation in degrees

Definition at line 387 of file Actor.cpp.

void Actor::SetColor ( float  r,
float  g,
float  b,
float  a = 1.0f 
)

Sets the color of the Actor with individual components.

Parameters
rRed
gGreen
bBlue
aAlpha (1.0f is opaque)

Definition at line 397 of file Actor.cpp.

void Actor::SetColor ( const Color color)

Sets the color of the Actor from a Color object.

Parameters
colorDesired color

Definition at line 402 of file Actor.cpp.

const Color & Actor::GetColor ( ) const

Return the Color of this Actor.

Returns
Actor's current color as a Color object

Definition at line 392 of file Actor.cpp.

void Actor::SetAlpha ( float  newAlpha)

Set the transparency of the Actor, independent of the other color components.

Parameters
newAlphaDesired transparency (1.0f is opaque, 0.0f is invisible)

Definition at line 407 of file Actor.cpp.

const float Actor::GetAlpha ( ) const

Get current transparency for this Actor.

Returns
Actor's current transparency value.

Definition at line 412 of file Actor.cpp.

void Actor::SetDrawShape ( actorDrawShape  drawShape)
virtual

Set the shape of the Actor when it's drawn.

See Also
actorDrawShape
Parameters
drawShapeDesired shape

Definition at line 229 of file Actor.cpp.

const actorDrawShape & Actor::GetDrawShape ( ) const

Get the current shape of this Actor.

Returns
Actor's shape

Definition at line 234 of file Actor.cpp.

void Actor::UseDisplayList ( int  listIndex)
inline

Use a display list index for drawing rather than a built-in shape.

Parameters
listIndexThe index to use (generate using glGenLists())

Definition at line 221 of file Actor.h.

void Actor::MoveTo ( const Vector2 newPosition,
float  duration,
bool  smooth = false,
String  onCompletionMessage = "" 
)

A "fire and forget" function that moves an Actor to a new position over a designated amount of time. This lets you handle movements without having to set up your own timers and keep track of them yourself. At the moment, it's limited to purely linear movement.

See Also
RotateTo
ChangeColorTo
ChangeSizeTo
Parameters
newPositionThe target position for the movement
durationHow long it should take to get there
smoothWhether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp
onCompletionMessageIf specified, a Message of this type will be sent when the movement is complete, letting you know when it's done. You will have to manually subscribe to this Message, though.

Definition at line 239 of file Actor.cpp.

void Actor::RotateTo ( float  newRotation,
float  duration,
bool  smooth = false,
String  onCompletionMessage = "" 
)

A "fire and forget" function that rotates an Actor over a designated amount of time.

See Also
MoveTo
Parameters
newRotationThe target rotation
durationHow long it should take
smoothWhether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp
onCompletionMessagethe type of Message to be sent on completion

Definition at line 245 of file Actor.cpp.

void Actor::ChangeColorTo ( const Color newColor,
float  duration,
bool  smooth = false,
String  onCompletionMessage = "" 
)

A "fire and forget" function that changes an Actor's color over a designated amount of time.

See Also
MoveTo
Parameters
newColorThe target color
durationHow long it should take
smoothWhether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp
onCompletionMessagethe type of Message to be sent on completion

Definition at line 251 of file Actor.cpp.

void Actor::ChangeSizeTo ( const Vector2 newSize,
float  duration,
bool  smooth = false,
String  onCompletionMessage = "" 
)

A "fire and forget" function that changes an Actor's size over a designated amount of time. This version uses a Vector2 if you want to set a non-uniform target size.

See Also
MoveTo
Parameters
newSizeThe target size
durationHow long it should take
smoothWhether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp
onCompletionMessagethe type of Message to be sent on completion

Definition at line 257 of file Actor.cpp.

void Actor::ChangeSizeTo ( float  newSize,
float  duration,
bool  smooth = false,
String  onCompletionMessage = "" 
)

A "fire and forget" function that changes an Actor's size over a designated amount of time.

See Also
MoveTo
Parameters
newSizeThe target size
durationHow long it should take
smoothWhether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp
onCompletionMessagethe type of Message to be sent on completion

Definition at line 263 of file Actor.cpp.

int Actor::GetSpriteTexture ( int  frame = 0) const

Gets the OpenGL texture reference that the Actor is currently using when it draws itself.

Parameters
frameIf the Actor has an animation, you can retrieve the reference for a specific frame
Returns
The OpenGL texture reference

Definition at line 430 of file Actor.cpp.

bool Actor::SetSprite ( const String &  filename,
int  frame = 0,
GLint  clampmode = GL_CLAMP,
GLint  filtermode = GL_LINEAR,
bool  optional = false 
)

Apply texture information to an Actor. The file can be any image format supported by DevIL, and transparency in the image will be used when drawing the Actor.

Parameters
filenameThe path to an image file
frameIf you're building an animation for this Actor, you can specify the frame to which this texture should be assigned.
clampmodeThe OpenGL clamp mode to use when drawing this sprite. can be either GL_CLAMP or GL_REPEAT.
filtermodeThe OpenGL filter mode to use when drawing this sprite. One of GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, or GL_LINEAR_MIPMAP_LINEAR
optionalIf set to true, the engine won't complain if it can't load this texture.
Returns
True if the sprite was successfully set, false otherwise

Definition at line 440 of file Actor.cpp.

void Actor::ClearSpriteInfo ( )

Remove all sprite information from an Actor

Definition at line 450 of file Actor.cpp.

void Actor::LoadSpriteFrames ( const String &  firstFilename,
GLint  clampmode = GL_CLAMP,
GLint  filtermode = GL_LINEAR 
)

A convenience function for loading up a directory of image files as an animation. We expect the name of the first image to end in _###, where

represents a number. The number of digits you put at the end

doesn't matter, but we are internally limited to 64 frames. If you want more, just change MAX_SPRITE_FRAMES in Actor.h.

From the first file that you pass the function, it will iterate through the file's directory and sequentially load up any images that follow the same naming pattern. So if you had a directory with anim_001.png, anim_002.png, and anim_003.png, you could load the three-frame animation by passing "anim_001.png" to this function.

Parameters
firstFilenameThe starting file for the animation
clampmodeThe clamp mode to be used by the SetSprite function
filtermodeThe filter mode to be used by the SetSprite function

Definition at line 488 of file Actor.cpp.

void Actor::PlaySpriteAnimation ( float  delay,
spriteAnimationType  animType = SAT_Loop,
int  startFrame = -1,
int  endFrame = -1,
const char *  animName = NULL 
)

Actually triggers the loaded animation to start playing.

Parameters
delayThe amount of time between frames
animTypeHow the animation should behave when it's finished. Options are SAT_Loop, SAT_PingPong, and SAT_OneShot.
startFrameThe starting frame of the animation to play
endFrameThe ending frame of the animation to play
animNameThe name of the animation so you can get the event when it finishes.

Definition at line 473 of file Actor.cpp.

void Actor::SetSpriteFrame ( int  frame)

Manually set the frame to draw. This way you can have an "animation" of frames that just represent states of your actor and swap between them without having to reload the textures all the time.

Parameters
frameThe frame to switch to

Definition at line 461 of file Actor.cpp.

int Actor::GetSpriteFrame ( ) const
inline

Get the current animation frame, ranging from 0 to MAX_SPRITE_FRAMES.

Returns
The current animation frame.

Definition at line 381 of file Actor.h.

const bool Actor::IsSpriteAnimPlaying ( ) const
inline

Lets you find out if an animation is currently playing on this Actor.

Returns
True if there's an animation playing, false if there isn't.

Definition at line 388 of file Actor.h.

virtual void Actor::AnimCallback ( String  animName)
inlinevirtual

A function you can override in the subclass if you you want your Actor to do certain things when an animation finishes. This function will get called by the animation system and pass in the string you assigned when calling PlaySpriteAnimation.

Parameters
animNameThe animation's name

Definition at line 401 of file Actor.h.

void Actor::SetUVs ( const Vector2 lowleft,
const Vector2 upright 
)

If you're doing fancy things with moving textures, this function lets you alter the UV (texture coordinates) of the actor.

Parameters
lowleftThe desired lower left UV
uprightThe desired upper right UV

Definition at line 582 of file Actor.cpp.

void Actor::GetUVs ( Vector2 lowleft,
Vector2 upright 
) const

Get the current UV coordinates being used by the Actor to draw.

Parameters
lowleftAn out parameter that will be set to the current lower left UV
uprightAn out parameter that will be set to the current upper right UV

Definition at line 594 of file Actor.cpp.

const bool Actor::IsTagged ( const String &  tag)

Returns whether or not this Actor has been given a particular tag.

See Also
TagCollection
Parameters
tagthe tag in question
Returns
True if the Actor has the tag

Definition at line 602 of file Actor.cpp.

void Actor::Tag ( const String &  newTag)

Adds a tag to an Actor. If the Actor already has this tag, no action is taken.

See Also
TagCollection
Parameters
newTagThe tag to add

Definition at line 616 of file Actor.cpp.

void Actor::Untag ( const String &  oldTag)

Removes a tag from an Actor. If the Actor doesn't have this tag, no action is taken.

See Also
TagCollection
Parameters
oldTagThe tag to remove

Definition at line 627 of file Actor.cpp.

const StringSet & Actor::GetTags ( ) const

Get all the tags for this ACtor.

See Also
TagCollection
Returns
A StringSet (std::vector<std::string>) of all the Actor's tags

Definition at line 634 of file Actor.cpp.

const String & Actor::SetName ( String  newName)

Give this Actor a name that can later be used as a unique identifier. The the actual name given may differ from what is passed in, but is guaranteed to be unique. (A global monotonically increasing number will be appended until the name is distinct.)

Parameters
newNameThe desired name
Returns
The actual name that was given

Definition at line 639 of file Actor.cpp.

const String & Actor::GetName ( ) const

Get the unique name assigned to this Actor.

Returns
The Actor's current name.

Definition at line 666 of file Actor.cpp.

Actor *const Actor::GetNamed ( const String &  nameLookup)
static

A static function of the Actor class which returns an Actor from a name.

Parameters
nameLookupThe name index to look for
Returns
The Actor with the given name. Will be NULL if there's no match

Definition at line 671 of file Actor.cpp.

virtual void Actor::ReceiveMessage ( Message message)
inlinevirtual

An implementation of the MessageListener interface, which will be called when a message gets delivered.

There is no actual implementation in the base class, but you can override in the subclass.

See Also
MessageListener
Parameters
messageThe message getting delivered.

Implements MessageListener.

Reimplemented in TextActor, and FullScreenActor.

Definition at line 494 of file Actor.h.

void Actor::SetLayer ( int  layerIndex)

Set a new rendering layer for this Actor.

Layers are ordered from bottom to top by index. No space is wasted by leaving empty layers in between, so feel free to pad out your indices if you want.

Parameters
layerIndexthe index of the render layer you want to assign

Definition at line 703 of file Actor.cpp.

void Actor::SetLayer ( const String &  layerName)

Set a new rendering layer for this Actor by the name of the layer.

The name of the layer has to be set up first by calling World::NameLayer. If you pass an invalid layer name, this Actor will be put on layer 0.

See Also
SetLayer
Parameters
layerNamethe name of the render layer you want to assign

Definition at line 708 of file Actor.cpp.

void Actor::Update ( float  dt)
virtual

A function which makes the necessary updates to the Actor. The base implementation just updates the animations and intervals, but a subclass override can perform whatever extra magic is necessary. Make sure to call the base class's Update if you subclass.

Parameters
dtThe amount of time that's elapsed since the beginning of the last frame.

Reimplemented from Renderable.

Reimplemented in Camera, ParticleActor, and Sentient.

Definition at line 110 of file Actor.cpp.

void Actor::Render ( )
virtual

A function to draw the Actor to the screen. By default, this does the basic drawing based on the texture, color, shape, size, position, and rotation that have been applied to the Actor. Can be overridden in a subclass if necessary.

This will get called on every Actor once per frame, after the Update.

Reimplemented from Renderable.

Reimplemented in Camera, TextActor, ParticleActor, HUDActor, and Sentient.

Definition at line 268 of file Actor.cpp.

virtual void Actor::LevelUnloaded ( )
inlinevirtual

Called for every actor that doesn't get unloaded in World::UnloadAll(). This is a good place to clear out any cached pointers, etc.

Definition at line 544 of file Actor.h.

Actor* Actor::GetSelf ( )
inline

Yes, this looks pointless and redundant. But it has a function for the scripting layer – it activates the inheritance downcasts so you can get a derived object from its base pointer.

In most instances, an Actor* getting thrown to the script layer will be wrapped correctly as a PhysicsActor, TextActor, etc. BUT, if it's coming from an STL container, then it won't. Rather than trying to fiddle with the SWIG typemaps which wrap the STL, this solution is more robust. It does require an extra call in the script, but c'est la vie.

Returns
the Actor's "this" pointer

Definition at line 560 of file Actor.h.

Actor * Actor::Create ( const String &  archetype)
static

Create an Actor from an archetype defined in a .lua file in Config/ActorDef. Automatically adds the Actor to the World.

The table names in the .lua files designate the name of the archetype, while the values in each table specify the properties for that archetype. Any function that can be called on an Actor can be used as a property – things like SetSize can be called simply "size."

Colors and Vectors can be defined as tables, so the following definition is valid.

my_actor = {
color = {1, 0, 1},
alpha = 0.5,
size = 5,
}
Parameters
archetypethe name of the Actor archetype (the table name from the .lua file)

Definition at line 684 of file Actor.cpp.

static void Actor::SetScriptCreatedActor ( Actor a)
inlinestatic

This static function is used internally by the scripting layer to let the core engine get at Actors that created in script. If that doesn't make complete sense to you, you probably have no need to call this function.

Parameters
aThe actor that was just created in script

Definition at line 598 of file Actor.h.

virtual const String Actor::GetClassName ( ) const
inlinevirtual

Used by the SetName function to create a basename for this class. Overridden in derived classes.

Returns
The string "Actor"

Reimplemented in PhysicsActor, Camera, ParticleActor, TextActor, FullScreenActor, and HUDActor.

Definition at line 606 of file Actor.h.

Member Data Documentation

const float Actor::_squareVertices
staticprotected
Initial value:
= {
-0.5f, 0.5f,
-0.5f, -0.5f,
0.5f, 0.5f,
0.5f, -0.5f,
}

Definition at line 617 of file Actor.h.


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