![]() |
Angel
A 2D Game Prototyping Engine
|
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 Vector2 & | GetSize () const |
| virtual void | SetPosition (float x, float y) |
| virtual void | SetPosition (const Vector2 &pos) |
| const Vector2 & | GetPosition () 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 Color & | GetColor () const |
| void | SetAlpha (float newAlpha) |
| const float | GetAlpha () const |
| void | SetDrawShape (actorDrawShape drawShape) |
| const actorDrawShape & | GetDrawShape () 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 () |
| Actor * | GetSelf () |
| virtual const String | GetClassName () |
Static Public Member Functions | |
| static Actor *const | GetNamed (const String &nameLookup) |
| static Actor * | Create (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 |
Static Protected Attributes | |
| static const float | _squareVertices [] |
| static float | _circleVertices [] |
| static float | _circleTextureCoords [] |
| static std::map< String, Actor * > | _nameList |
| static Actor * | _scriptCreatedActor = NULL |
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.
| Actor::Actor | ( | ) |
| Actor::~Actor | ( | ) | [virtual] |
| void Actor::SetSize | ( | float | x, |
| float | y = -1.f |
||
| ) |
Set the size of this Actor.
| x | Horizontal size in OpenGL units -- negative numbers treated as zero |
| y | Vertical size in OpenGL units -- if less than or equal to zero, assumed to be equal to x |
Reimplemented in PhysicsActor.
| void Actor::SetSize | ( | const Vector2 & | newSize | ) |
| const Vector2 & Actor::GetSize | ( | ) | const |
| void Actor::SetPosition | ( | float | x, |
| float | y | ||
| ) | [virtual] |
| void Actor::SetPosition | ( | const Vector2 & | pos | ) | [virtual] |
| const Vector2 & Actor::GetPosition | ( | ) | const |
| void Actor::SetRotation | ( | float | rotation | ) | [virtual] |
| const float Actor::GetRotation | ( | ) | const |
| void Actor::SetColor | ( | float | r, |
| float | g, | ||
| float | b, | ||
| float | a = 1.0f |
||
| ) |
| void Actor::SetColor | ( | const Color & | color | ) |
| const Color & Actor::GetColor | ( | ) | const |
| void Actor::SetAlpha | ( | float | newAlpha | ) |
| const float Actor::GetAlpha | ( | ) | const |
| void Actor::SetDrawShape | ( | actorDrawShape | drawShape | ) |
Set the shape of the Actor when it's drawn.
| drawShape | Desired shape |
| const actorDrawShape & Actor::GetDrawShape | ( | ) | const |
| void Actor::UseDisplayList | ( | int | listIndex | ) | [inline] |
| 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.
| newPosition | The target position for the movement |
| duration | How long it should take to get there |
| smooth | Whether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp |
| onCompletionMessage | If 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. |
| 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.
| newRotation | The target rotation |
| duration | How long it should take |
| smooth | Whether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp |
| onCompletionMessage | the type of Message to be sent on completion |
| 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.
| newColor | The target color |
| duration | How long it should take |
| smooth | Whether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp |
| onCompletionMessage | the type of Message to be sent on completion |
| 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.
| newSize | The target size |
| duration | How long it should take |
| smooth | Whether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp |
| onCompletionMessage | the type of Message to be sent on completion |
| 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.
| newSize | The target size |
| duration | How long it should take |
| smooth | Whether the function should use MathUtil::SmoothStep instead of MathUtil::Lerp |
| onCompletionMessage | the type of Message to be sent on completion |
| int Actor::GetSpriteTexture | ( | int | frame = 0 | ) | const |
| 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.
| filename | The path to an image file |
| frame | If you're building an animation for this Actor, you can specify the frame to which this texture should be assigned. |
| clampmode | The OpenGL clamp mode to use when drawing this sprite. can be either GL_CLAMP or GL_REPEAT. |
| filtermode | The 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 |
| optional | If set to true, the engine won't complain if it can't load this texture. |
| void Actor::ClearSpriteInfo | ( | ) |
| 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.
| 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.
| delay | The amount of time between frames |
| animType | How the animation should behave when it's finished. Options are SAT_Loop, SAT_PingPong, and SAT_OneShot. |
| startFrame | The starting frame of the animation to play |
| endFrame | The ending frame of the animation to play |
| animName | The name of the animation so you can get the event when it finishes. |
| void Actor::SetSpriteFrame | ( | int | frame | ) |
| int Actor::GetSpriteFrame | ( | ) | const [inline] |
| const bool Actor::IsSpriteAnimPlaying | ( | ) | const [inline] |
| virtual void Actor::AnimCallback | ( | String | animName | ) | [inline, virtual] |
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.
| animName | The animation's name |
| const bool Actor::IsTagged | ( | const String & | tag | ) |
Returns whether or not this Actor has been given a particular tag.
| tag | the tag in question |
| void Actor::Tag | ( | const String & | newTag | ) |
Adds a tag to an Actor. If the Actor already has this tag, no action is taken.
| newTag | The tag to add |
| void Actor::Untag | ( | const String & | oldTag | ) |
Removes a tag from an Actor. If the Actor doesn't have this tag, no action is taken.
| oldTag | The tag to remove |
| const StringSet & Actor::GetTags | ( | ) | const |
Get all the tags for this ACtor.
| 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. (Numbers will be appended until the name is distinct.)
| newName | The desired name |
| const String & Actor::GetName | ( | ) | const |
| Actor *const Actor::GetNamed | ( | const String & | nameLookup | ) | [static] |
| virtual void Actor::ReceiveMessage | ( | Message * | message | ) | [inline, virtual] |
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.
| message | The message getting delivered. |
Implements MessageListener.
Reimplemented in TextActor, and FullScreenActor.
| 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.
| layerIndex | the index of the render layer you want to assign |
| 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.
| layerName | the name of the render layer you want to assign |
| 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.
| dt | The amount of time that's elapsed since the beginning of the last frame. |
Reimplemented from Renderable.
Reimplemented in ParticleActor, and Sentient.
| 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, ParticleActor, TextActor, HUDActor, and Sentient.
| virtual void Actor::LevelUnloaded | ( | ) | [inline, virtual] |
Called for every actor that doesn't get unloaded in World::UnloadAll(). This is a good place to clear out any cached pointers, etc.
| 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.
| 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,
}
| archetype | the name of the Actor archetype (the table name from the .lua file) |
| static void Actor::SetScriptCreatedActor | ( | Actor * | a | ) | [inline, static] |
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.
| a | The actor that was just created in script |
| virtual const String Actor::GetClassName | ( | ) | [inline, virtual] |
Used by the SetName function to create a basename for this class. Overridden in derived classes.
Reimplemented in ParticleActor, FullScreenActor, and HUDActor.
const float Actor::_squareVertices [static, protected] |


1.7.5.1