Constructor
new MapMover(x, y, width, height, map, caopt, dontCloneMapopt, dtopt, twopt, thopt, mapRowsopt, mapColumnsopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
Number | The x location of the MapMover |
||
y |
Number | The y location of the MapMover |
||
width |
Number | The width of the MapMover |
||
height |
Number | The height of the MapMover |
||
map |
Array | A 2D Array denoting the area that the MapMover 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] ];
|
||
ca |
CanvasAnimation |
<optional> |
The optional CanvasAnimation associated with this MapMover. |
|
dontCloneMap |
Boolean |
<optional> |
false | If true is passed the map you pass in will not be cloned, otherwise the map you pass in is cloned, truly cloned, such that your constructed MapMover.map is Not a reference to your original map. The default opperation is to leave this alone, allowing your map to get cloned. See BlitMath.cloneMultiArray |
dt |
Number |
<optional> |
.6666666667 | delta time based on desired frame rate, the default is Tabageos.TimeKeeper._sae; 1000 / 60. Change the value of Tabageos.TimeKeeper._sae if you want to adjust the frame rate of your game. Default is 1000 / 60. for 60 frames per second. |
tw |
Number |
<optional> |
The width of each tile in the map, default will be same as width |
|
th |
Number |
<optional> |
The height of each tile in the map, default will be same as height |
|
mapRows |
Number |
<optional> |
The amount of rows the map has. Optional, by default this will be calculated based on map. |
|
mapColumns |
Number |
<optional> |
The amount of columns the map has. Optional, by default this will be calculated based on map. |
Members
_atCeiling
Denotes if the MapMover is colliding up. This property is set via the update method.
_canvasAnimation
A reference to the optional CanvasAnimation that is associated with this MapMover. The CanvasAnimation would be used to display and animate the MapMover on a CanvasObject.
_gravityLevel
Default is .285, this only applies if _jumps is 1.
_grounded
Denotes if the MapMover is colliding down. This property is set via the update method.
_jumps
If 1 then gravity will be applied to the MapMover. Platformer movement. By default _jumps is 0 for MapMovers. Topdown movement.
_jumpSpeed
_map
The 2D Array that the MapMover is confined to.
_npLeft
_pLeft
Denotes if the MapMover is colliding left. This property is set via the update method.
_pRight
Denotes if the MapMover is colliding right. This property is set via the update method.
_state
1 is idle 2 is left and right 3 is up 4 is down, only when _jumps is 1.
The move method uses this property, if it gets changed before move is called, then the move method would start from that state.
_th
The tile height of each tile in the map, default is 16.
_tw
The tile width of each tile in the map, default is 16.
_walkSpeed
Default is 4.
constructor
down
stand
up
walk
Methods
(static) setupForTileMove()
Set up the MapMover 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}
Used by the update method
Name | Type | Description |
---|---|---|
last |
||
curr |
||
veloc |
||
map |
||
tw |
||
th |
The y position of the collision
- Type
- Number
isHeadHitOnMap(last, curr, veloc, map, tw, th) → {Number}
Used by the update method
Name | Type | Description |
---|---|---|
last |
||
curr |
||
veloc |
||
map |
||
tw |
||
th |
The y position of the collision
- Type
- Number
isLeftPushingOnMap(last, curr, veloc, map, tw, th) → {Number}
Used by the update method
Name | Type | Description |
---|---|---|
last |
||
curr |
||
veloc |
||
map |
||
tw |
||
th |
The x position of the collision
- Type
- Number
isRightPushingOnMap(last, curr, veloc, map, tw, th) → {Number}
Used by the update method
Name | Type | Description |
---|---|---|
last |
||
curr |
||
veloc |
||
map |
||
tw |
||
th |
The x position of the collision
- Type
- Number
move(left, right, up, down)
Moves the MapMover, in the directions given, confined to the map given during construction.
Name | Type | Description |
---|---|---|
left |
Boolean | |
right |
Boolean | |
up |
Boolean | |
down |
Boolean |
update(dontApplyToXY)
This methos is called by the move method, and is the method handling _pos updates and collisions.
Name | Type | Description |
---|---|---|
dontApplyToXY |
Boolean |