Constructor
new MapTraveler(x, y, width, height, map, caopt, dontCloneMapopt, dtopt, tileWopt, tileHopt, mapRowsopt, mapColumnsopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
Number | The x location of the MapTraveler |
||
y |
Number | The y location of the MapTraveler |
||
width |
Number | The width of the MapTraveler |
||
height |
Number | The height of the MapTraveler |
||
map |
Array | The 2D Array map the MapTraveler should be confined to. see _map |
||
ca |
CanvasAnimation |
<optional> |
Optional CanvasAnimation to display and animate the MapTraveler |
|
dontCloneMap |
Boolean |
<optional> |
false | Optional to not clone the map that is passed in during construction. |
dt |
Number |
<optional> |
.6666666667 | Optiona delta time value, default is TimeKeeper._sae .6666666667 see TimeKeeper. |
tileW |
Number |
<optional> |
The default tile width for each tile in the map. |
|
tileH |
Number |
<optional> |
The default tile height for each tile in the map. |
|
mapRows |
Number |
<optional> |
The amount of rows that the map has. |
|
mapColumns |
Number |
<optional> |
The amount of columns that the map has. |
- See:
Members
_atCeiling
Denotes that the MapTraveler is colliding upward. This value should not be manually changed, the .update method calculates this value.
_canvasAnimation
A reference to the CanvasAnimation passed in during construction.
_gravityLevel
The amount of gravity to apply for jumping, defaut is .285.
_grounded
Denotes if the MapTraveler is colliding downward. This value should not be manually changed, the .update method calculates this value.
_jumps
If _jumps is 1 then the MapTraveler will jump up and fall back down having gravity applied when falling, if _jumps is 0 it will move in all directions in the same manner. _jumps is 0 by default for MapTravelers.
_jumpSpeed
_jumpSpeed affects how fast it jumps up when _jumps is 1. _veloc.y is set to this value for jumping during move calls.
_map
A 2D Array denoting the area that the MapTraveler can move in. The map can be a 2D Array with integer inner values as follows; var map = [ [1,0,0,0,0,1], [1,0,0,0,0,1], [1,0,0,0,0,1], [1,1,1,1,1,1] ];
(In the above case, it would only be able to move in the 0 spots)
Or the map can be a 2D Array with Array inner values as follows;
var map = [
[[1,1],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[0,0],[0,0],[0,0],[1,1]],
[[1,1],[2,2],[2,2],[2,2],[1,1]]
];
(In the above case, it would only be able to move in the [0,0] spots)
(this map type can denote much more and is the default type for the BlitMath Class which is a map drawing helper class)
_pLeft
Denotes if the MapTravelers is colliding left. This value should not be manually changed, the .update method calculates this value.
_pRight
Denotes if the MapTraveler is colliding right. This value should not be manually changed, the .update method calculates this value.
_state
The current state of the MapTraveler, 1 2 3 or 4; stand, walk, up down.
_th
The default tile height of each tile in the map.
_tw
The default tile width of each tile in the map.
_walkSpeed
_walkSpeed defines how fast it will move horizontally, _veloc.x is set to this value during .move calls.
constructor
destination
A MoverPoint the MapTraveler is going to, can be used with the methods inherited from TravelerSkeleton.
down
The down state: 4.
health
A value present so that one can use it.
stand
The stand state: 1.
up
The up state: 3.
walk
The walk state: 2.
Methods
(static) setupForTileMove()
Set up the MapTraveler to move tile by tile instead of fluidly.
This method sets the following variables accordingly:
_jumps = 0; _deltaTime = 1; _jumpSpeed = tile width; ,maxSpeed = tile width. _walkSpeed = tile width.
(static) tileMove(left, right, up, down)
Move tile by tile, call setupForTileMove once first, then you can use this method instead of move, also cancel all button presses after the call. Also, if using the touch controller, you would want the touch controller to not capture touch move, so you would call removeTouchMove on the ControllerPad instance. See the frogger example.
Name | Type | Description |
---|---|---|
left |
Boolean | |
right |
Boolean | |
up |
Boolean | |
down |
Boolean |
isGroundedOnMap(last, curr, veloc, map, tw, th) → {Number}
Returns where the MapTraveler is touching the ground based on the map given. The update method uses this method using the params given during construction of the Class. The ._grounded property is set by the update method based on this method.
Name | Type | Description |
---|---|---|
last |
MoverPoint | this._lastPost |
curr |
MoverPoint | this._pos |
veloc |
MoverPoint | this._veloc |
map |
Array | this._map |
tw |
Number | this._tw |
th |
Number | this._th |
- Type
- Number
isHeadHitOnMap(last, curr, veloc, map, tw, th) → {Number}
Returns where the MapTraveler is touching a ceiling based on the map given. The update method uses this method using the params given during construction of the Class. The ._atCeiling property is set by the update method based on this method.
Name | Type | Description |
---|---|---|
last |
MoverPoint | this._lastPost |
curr |
MoverPoint | this._pos |
veloc |
MoverPoint | this._veloc |
map |
Array | this._map |
tw |
Number | this._tw |
th |
Number | this._th |
- Type
- Number
isLeftPushingOnMap(last, curr, veloc, map, tw, th) → {Number}
Returns where the MapTraveler is colliding left based on the map given. The update method uses this method using the params given during construction of the Class. The ._pLeft property is set by the update method based on this method.
Name | Type | Description |
---|---|---|
last |
MoverPoint | this._lastPost |
curr |
MoverPoint | this._pos |
veloc |
MoverPoint | this._veloc |
map |
Array | this._map |
tw |
Number | this._tw |
th |
Number | this._th |
- Type
- Number
isRightPushingOnMap(last, curr, veloc, map, tw, th) → {Number}
Returns where the MapTraveler is colliding right based on the map given. The update method uses this method using the params given during construction of the Class. The ._pRight property is set by the update method based on this method.
Name | Type | Description |
---|---|---|
last |
MoverPoint | this._lastPost |
curr |
MoverPoint | this._pos |
veloc |
MoverPoint | this._veloc |
map |
Array | this._map |
tw |
Number | this._tw |
th |
Number | this._th |
- Type
- Number
move(left, right, up, down, dontApplyForceopt)
Moves the MapTraveler left, right, up, and down and confines it to the map given during construction. Velocity is controlled by this method, it gets set to either _walkSpeed or _jumpSpeed based on the paramaters passed and the current _state of the MapTraveler. This method opperates and results in the same behavior as the MapMover Class if dontApplyForce is true (or 1). [ by default it is false] If dontApplyForce is left out [false] forceApplier is used and therefore maxForce, mass, and maxSpeed are applied to velocity. All the TravelerSkeleton methods change and use forceApplier. The move method encapsulates and controlls .update calls, dontApplyForce is also available as the last param of the update method. But to fully utilize the Traveler aspect of this Class, MapTraveler, one would adjust the velocity (_veloc), or use one of the TravelerSkeleton inherited methods, then use update without the move method. (see update)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
left |
Boolean | |||
right |
Boolean | |||
up |
Boolean | |||
down |
Boolean | |||
dontApplyForce |
Boolean |
<optional> |
false | Default is false. |
update(dontApplyToXYopt, dontApplyForceopt)
The update method applies velocity to the position of the MapTraveler, and then only changes velocity to 0 if there is collision. One could utilze TravelerSkeleton methods as follows; var mt = new tabageos.MapTraveler( ... ); mt._veloc.x = 1; mt.easeTo(MoverPoint); mt.update();
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dontApplyToXY |
Boolean |
<optional> |
false | If true, x and y are not updated, ._pos and just ._veloc (velocity). |
dontApplyForce |
Boolean |
<optional> |
false | If true, forceApplier will not be used and therefore the method opperates the same way as a MapMover, to utilize the TravelerSkeleton inherited methods this value must be the default false. |