new b5.MapActor(){b5.MapActor}
A MapActor is derived from a b5.Actor that displays tiled map game objects instead of a single image and inherits all properties, methods and so forth from its parent. A MapActor 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 MapActor:
var map = new b5.MapActor(); // Create instance of actor
map.map_width = 100; // Set map width in cells
map.map_height = 100; // Set map height in cells
map.display_width = 16; // Set how many cells to display on x axis
map.display_height = 16; // Set how many cells to display on y axis
map.generateTiles(32, 64, 64, 256); // Generate the tile set
map.bitmap = new b5.Bitmap("tiles", "testmap.png", true); // Set tile set bitmap
for (var t = 0; t < map.map_width * map.map_height; t++) // Generate a random map
map.map.push((Math.random() * 32) << 0);
scene.addActor(map); // Add to scene for processing and drawing
For a complete overview of the Actor class see Booty5 Actor Overview
Properties:
Name | Type | Description |
---|---|---|
tiles |
Array.<object> | Array of tiles (tiles contain x,y offsets of each tile in source bitmap) |
map |
Array.<number> | Array of tile indices, each index is an index into the tile set |
collision_map |
Array.<number> | Array of collision tile indices |
tile_width |
number | Width of each tile |
tile_height |
number | Height of each tiles |
map_width |
number | Width of map in tiles |
map_height |
number | Height of map in tiles |
display_width |
number | Map display width in tiles |
display_height |
number | Map display height in tiles |
Returns:
Type | Description |
---|---|
b5.MapActor | The created MapActor |
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/mapActor.js, line 215 -
Overrides the base b5.Actor.draw() method to draw a tiled map instead of an image
-
inherited drawToCache()
actor/actor.js, line 1434 -
Renders this actor to a cache which can speed up rendering it the next frame
-
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 -
generateTiles(count, tile_w, tile_h, bitmap_w)
actor/mapActor.js, line 80 -
Generates a group of tiles (a tile set) from the supplied parameters
Name Type Description count
number Total number of tiles to generate
tile_w
number Width of each tile
tile_h
number Height of each tile
bitmap_w
number Width of tile set bitmap
-
getTile(x, y, collision){number}
actor/mapActor.js, line 127 -
Gets the tile index at map cell x,y
Name Type Description x
number Map horizontal cell coordinate
y
number Map vertical cell coordinate
collision
boolean If true then returned tile will be taken from collision map instead of visual map
Returns:
Type Description number The tile index -
getTileFromPosition(x, y, collision){number|*}
actor/mapActor.js, line 206 -
Gets the map tile at cell position x, y
Name Type Description x
number Scene coordinate on x-axis
y
number Scene coordinate on y-axis
collision
boolean If true then returned tile will be taken from collision map instead of visual map
Returns:
Type Description number | * -
getTilePosition(x, y, position){Object}
actor/mapActor.js, line 177 -
Calculates the scene coordinate for the specified edge of a tile. The supplied position can be one of the following:
Name Type Description x
number x-axis coordinate in scene space
y
number y-axis coordinate in scene space
position
string Can be one of the following strings:
- "t" - Returns coordinate of top edge of tile
- "m" - Returns coordinate of middle of tile
- "b" - Returns coordinate of bottom edge of tile
- "l" - Returns coordinate of left edge of tile
- "c" - Returns coordinate of centre of tile
- "r" - Returns coordinate of right edge of tile
Returns:
Type Description Object The tiles coordinate {x, y} -
getTileXY(x, y){Object}
actor/mapActor.js, line 148 -
Converts the supplied scene coordinate to a map cell coordinate
Name Type Description x
number x-axis coordinate in scene space
y
number y-axis coordinate in scene space
Returns:
Type Description Object Map cell coordinate {x, y} -
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
-
setTile(x, y, tile, collision)
actor/mapActor.js, line 105 -
Sets the tile at map cell x,y
Name Type Description x
number Map horizontal cell coordinate
y
number Map vertical cell coordinate
tile
number Tile number to set to cell
collision
boolean If true then tile in the collision map will be written instead of visual map
-
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