new b5.LabelActor(){b5.LabelActor}
A LabelActor is derived from a b5.Actor that displays text game objects instead of an image and inherits all properties, methods and so forth from its parent. A LabelActor should be added to a b5.Scene or another b5.Actor that is part of a scene hierarchy
Examples
Example showing how to create a LabelActor:
var actor = new b5.LabelActor();
actor.font = "16pt Calibri"; // Set font
actor.text_align = "center"; // Set horizontal alignment
actor.text_baseline = "middle"; // Set vertical alignment
actor.fill_style = "#ffffff"; // Set fill style
actor.text = "Hello World"; // Set some text
scene.addActor(actor); // Add to scene for processing and drawing
For a complete overview of the Actor class see Booty5 Actor Overview
Properties:
Name | Type | Description |
---|---|---|
text |
string | The text to display |
font |
string | The font to display the text in (e.g. 16px Calibri) |
text_align |
string | Text horizontal alignment (left, right or center) |
text_baseline |
string | Text vertical alignment (top, middle or bottom) |
fill_style |
string | Style used to fill the label (default is #ffffff) |
stroke_style |
string | Stroke used to draw none filled label (default is #ffffff) |
stroke_thickness |
number | Stroke thickness for none filled (default is #ffffff) |
filled |
boolean | If true then label interior will be filled otherwise empty (default is true) |
Returns:
Type | Description |
---|---|
b5.LabelActor | The created LabelActor |
Extends
Methods
-
Adds the specified actor to this actors child list, placing the specified actor under control of this actor
Name Type Description actor
b5.Actor An actor
Returns:
Type Description b5.Actor The supplied actor -
inherited addFixture(options){object}
actor/actor.js, line 972 -
Adds a new fixture to this actors physics body
Name Type Description options
object An object describing the fixtures properties:
- type {number} – Type of fixture (Shape.TypeBox, Shape.TypeCircle or Shape.TypePolygon)
- density {number} – Fixture density
- friction {number} – Fixture friction
- restitution {number} – Fixture restitution
- is_sensor {boolean} – true if this fixture is a sensor
- width {number} – Width and height of box (if type is box)
- height {number} – Width and height of box (if type is box)
- radius {number} – Radius of shape (if type is circle)
- material {b5.Material} – A Material resource, if passed then density, friction, restitution will be taken from the material resource
- shape {b5.Shape} – A Shape resource, if passed then width, height, type and vertices will be taken from the shape resource
Returns:
Type Description object The created fixture or in the case of a multi-fixture shape an array of fixtures -
inherited addJoint(options){object}
actor/actor.js, line 1087 -
Adds a new joint to this actor
Name Type Description options
object An object describing the joints properties:
- type {string} – Type of joint to create (weld, distance, revolute, prismatic, pulley, wheel, mouse)
- actor_b (b5.Actor) – The other actor that this joint attaches to
- anchor_a {object} - The joints x, y anchor point on this body
- anchor_b {object} - The joints x, y anchor point on actor_b’s body
- self_collide {boolean} – If set to true then actors that are connected via the joint will collide with each other
- frequency {number} – Oscillation frequency in Hertz (distance joint)
- damping {number} – Oscillation damping ratio (distance and wheel joints)
- limit_joint {boolean} – If true then joint limits will be applied (revolute, prismatic, wheel joints)
- lower_limit {number} – Lower limit of joint (revolute, prismatic, wheel joints)
- upper_limit {number} – Upper limit of joint (revolute, prismatic, wheel joints)
- motor_enabled {boolean} – If true then the joints motor will be enabled (revolute, prismatic, wheel joints)
- motor_speed {number} – Motor speed (revolute, prismatic, wheel joints)
- max_motor_torque {number} – Motors maximum torque (revolute joints)
- max_motor_force {number} – Motors maximum force (prismatic, wheel, mouse joints)
- axis {object} – Movement x, y axis (prismatic, wheel joints)
- ground_a {object} – Ground x, y offset for this actor (pulley joints)
- ground_b {object} – Ground x, y offset for actor_b (pulley joints)
Returns:
Type Description object The created joint -
inherited baseUpdate(dt)
actor/actor.js, line 1527 -
Main base actor update method that is called by the main app object each logic loop. Performs many actions including:
- Calling onTick() callback
- Updating local timelines manager
- Updating local actions manager
- Updating local tasks manager
- Providing virtual canvas functionality
- Updating bitmap animation
- Updating position / rotation from physics or updating arcade physics
- Scene edge wrapping
- Applying docking
- Updating child hierarchy
- Cleaning up destroyed child actors
- Sorting child actor layers
Name Type Description dt
number Time that has passed since this actor was last updated in seconds
-
inherited bringToFront()
actor/actor.js, line 795 -
Moves the actor to the end of its parents child list, effectively rendering it on top of all other actors that have the same depth
-
inherited changeParent(parent)
actor/actor.js, line 600 -
Removes the actor from its current parent and places it into a new parent
Name Type Description parent
b5.Actor | b5.Scene New parent
-
inherited destroy()
actor/actor.js, line 587 -
Destroys the actor, removing it from the scene
-
inherited dirty()
actor/actor.js, line 1670 -
Dirties this actor and all child actor transforms forcing them to be rebuilt
-
draw()
actor/labelActor.js, line 71 -
Overrides the base b5.Actor.draw() method to draw a label instead of an image
-
drawToCache()
actor/labelActor.js, line 145 -
Overrides the base b5.Actor.drawToCache() method to draw a label to a cache
-
Searches the actors children to find the named actor
Name Type Description name
string Name of actor to find
recursive
boolean If true then this actors entire child actor hierarchy will be searched
Returns:
Type Description b5.Actor The found actor or null if not found -
Searches the actors children to find the actor by its id
Name Type Description id
number Id of actor to find
recursive
boolean If true then this actors entire child actor hierarchy will be searched
Returns:
Type Description b5.Actor The found actor or null if not found -
Search up the actors parent hierarchy for the first actor that is cached
Returns:
Type Description b5.Actor The found actor or null if not found -
Search up the actors parent hierarchy for the first actor parent of this actor
Returns:
Type Description b5.Actor The found actor or null if not found -
Tests to see if the supplied position has hit the actor or any of its children. This function does not work with actors that have been rotated around any point except their centre, also does not work with actors that have depth.
Name Type Description position
object The x,y position to be tested
Returns:
Type Description b5.Actor The actor that was hit or null if no actor was hit -
inherited initBody(body_type, fixed_rotation, is_bullet){object}
actor/actor.js, line 934 -
Creates and attached a physics body 5to this actor, placing this actor under control of the Box2D physics system
Name Type Description body_type
string Type of body, can be static, dynamic or kinematic.
fixed_rotation
boolean If set to true then the physics body will be prevented from rotating
is_bullet
boolean If set to true then the physics body will be marked as a bullet which can be useful for very fast moving objects
Returns:
Type Description object The created body -
inherited makeVirtual()
actor/actor.js, line 1695 -
Attaches a virtual canvas providing new actor properties:
- prev_scroll_pos_x {number} - Previous canvas scroll X position
- prev_scroll_pos_y {number} - Previous canvas scroll Y position
- scroll_pos_x {number} - Canvas scroll X position
- scroll_pos_y {number} - Canvas scroll Y position
- scroll_vx {number} - Canvas scroll X velocity
- scroll_vy {number} - Canvas scroll Y velocity
- scroll_range {number} - Scrollable range of canvas (left, top, width, height)
Child actors that apply docking will be docked to this container instead of the scene
-
inherited onBeginTouchBase(touch_pos)
actor/actor.js, line 854 -
Called by the main app object when the user begins to touch this actor, provided that this actor is marked as touchable Calls a user supplied onBeginTouch() method if one is supplied
Name Type Description touch_pos
object x,y position of touch
-
inherited onEndTouchBase(touch_pos)
actor/actor.js, line 869 -
Called by the main app object when the user stops touching this actor, provided that this actor is marked as touchable Calls a user supplied onEndTouch() method if one is supplied
Name Type Description touch_pos
object x,y position of touch
-
inherited onMoveTouchBase(touch_pos)
actor/actor.js, line 887 -
Called by the main app object when the user moves their finger or mouse whilst touching this actor, provided that this actor is marked as touchable Calls a user supplied onEndTouch() method if one is supplied
Name Type Description touch_pos
object x,y position of touch
-
inherited overlaps(other){boolean}
actor/actor.js, line 1947 -
Basic test to see if actors overlap (no scaling, rotation, origin or shape currently taken into account)
Name Type Description other
b5.Actor Other actor to test overlap with
Returns:
Type Description boolean true if overlapping, false if not -
inherited playAnim(name)
actor/actor.js, line 553 -
Plays the named animation of the attached b5.ImageAtlas brush on this actor
Name Type Description name
string Name of animation to play
-
inherited postDraw()
actor/actor.js, line 1500 -
Called after rendering the actor to perform various post-draw activities such as disabling shadows and resetting composite operations
-
inherited preDraw()
actor/actor.js, line 1482 -
Called before rendering the actor to perform various pre-draw activities such as setting opacity, shadows and composite operations
-
inherited release()
actor/actor.js, line 576 -
Releases the actor, calling the actors onDestroy() handler and releases physics, does not remove actor from the scene
-
inherited releaseBody()
actor/actor.js, line 905 -
Releases this actors physics body destroying the body, taking control of the actor from the Box2D physics system
-
inherited releaseJoints()
actor/actor.js, line 917 -
Releases all joints that this actor created, destroying the joints
-
inherited removeActor(actor)
actor/actor.js, line 640 -
Removes the specified actor from this actors child list
Name Type Description actor
b5.Actor An actor
-
inherited removeActorsWithTag(tag)
actor/actor.js, line 649 -
Removes all actors from this actors child list that match the specified tag
Name Type Description tag
string Actor tag
-
inherited removeJoint(joint)
actor/actor.js, line 1213 -
Removes and destroys the specified joint
Name Type Description joint
object The joint to remove
-
inherited sendToBack()
actor/actor.js, line 822 -
Moves the actor to the start of its parents child list, effectively rendering behind all other actors that have the same depth
-
inherited setDepth(depth)
actor/actor.js, line 540 -
Sets the actors 3D depth
Name Type Description depth
number 3D depth, use 0 to disable depth projection
-
inherited setOrigin(x, y)
actor/actor.js, line 495 -
Sets the actors render origin
Name Type Description x
number X coordinate
y
number Y coordinate
-
inherited setPosition(x, y)
actor/actor.js, line 471 -
Sets the actors scene position
Name Type Description x
number X coordinate
y
number Y coordinate
-
inherited setRotation(angle)
actor/actor.js, line 522 -
Sets the actors rotation
Name Type Description angle
number Angle in radians
-
inherited setScale(x, y)
actor/actor.js, line 509 -
Sets the actors scale
Name Type Description x
number X scale
y
number Y scale
-
inherited transformPoint(x, y){object}
actor/actor.js, line 1899 -
Transforms supplied point by actors visual transform
Name Type Description x
number X coordinate local to actor
y
number Y coordinate local to actor
Returns:
Type Description object Transformed point -
inherited update(dt)
actor/actor.js, line 1649 -
Main actor update method that is called by the main app object each logic loop. If you derive your own Actor class then you should override this method to provide your own functionality, but remember to call baseUpdate() if you would like to keep the existing base Actor functionality
Name Type Description dt
number Time that has passed since this actor was last updated in seconds
-
inherited updateParentTransforms()
actor/actor.js, line 778 -
Updates the transforms of all parents of this actor
-
inherited updateToPhysics()
actor/actor.js, line 1657 -
Copies actor velocities to the physics body
-
inherited updateTransform()
actor/actor.js, line 1235 -
Checks if this actors visual transform is dirty and if so rebuilds the transform and mark the transform as clean