Skip to content

Commit

Permalink
Update description
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Dec 18, 2024
1 parent 422235d commit e3fcd92
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 9 deletions.
29 changes: 29 additions & 0 deletions docs/docs/board.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Core object of Board system.
- [Triangle to tileXY array](https://codepen.io/rexrainbow/pen/wLYmyw)
- [Ellipse to tileXY array](https://codepen.io/rexrainbow/pen/LYYJmxE)
- [Bounds](https://codepen.io/rexrainbow/pen/PoeZOGo)
- [Boundary points](https://codepen.io/rexrainbow/pen/zxOoXPN)

## Usage

Expand Down Expand Up @@ -1195,6 +1196,34 @@ Offset all of tile positions to `(0, 0)`, and set board size to fit these tile p
graphics.strokePoints(points, true);
```
### Boundary points around tiles
- Get boundary points around tiles
```javascript
var pointsAarray = board.getBoundaryPoints(tileXYArray);
```
or
```javascript
var pointsAarray = board.getBoundaryPoints(chessArray);
```
or
```javascript
var pointsAarray = board.getBoundaryPoints(tileZ); // All tiles on tileZ
```
or
```javascript
var pointsAarray = board.getBoundaryPoints(); // All tileXY position
```
- Draw grid polygon on [graphics object](graphics.md#lines)
```javascript
pointsAarray.forEach(function (points) {
graphics
.lineStyle(lineWidth, color, alpha)
.strokePoints(points, true);
})
```
### Bounds
#### Board bounds
Expand Down
9 changes: 9 additions & 0 deletions docs/docs/gameobject.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ var output = gameObject.getCenter(output); // output: {x, y}
var output = gameObject.getBounds(output); // output: {x, y, width, height}
```

Draw bounds on [graphics](graphics.md)

```javascript
// var graphics = scene.add.graphics();
graphics
.lineStyle(lineWidth, color, alpha)
.strokeRectShape(gameObject.getBounds());
```

### Origin

- Get
Expand Down
18 changes: 9 additions & 9 deletions examples/board/get-boundary-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ class Demo extends Phaser.Scene {
width: 20,
height: 20
})
.forEachTileXY(function (tileXY, board) {
if (Math.random() < 0.5) {
var chess = this.rexBoard.add.shape(board, tileXY.x, tileXY.y, 0, 0x333333);
}
}, this);
.forEachTileXY(function (tileXY, board) {
if (Math.random() < 0.5) {
var chess = this.rexBoard.add.shape(board, tileXY.x, tileXY.y, 0, 0x333333);
}
}, this);

var boundaries = board.getBoundaryPoints(0);
for (var i = 0, cnt = boundaries.length; i < cnt; i++) {
graphics.lineStyle(2, 0xff0000, 1).strokePoints(boundaries[i], true);
}
var pointsAarray = board.getBoundaryPoints(0);
pointsAarray.forEach(function (points) {
graphics.lineStyle(2, 0xff0000, 1).strokePoints(points, true);
})
}

update() { }
Expand Down
10 changes: 10 additions & 0 deletions plugins/board/board/LogicBoard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,16 @@ declare class Board<ChessType = unknown> extends EE {
out?: Rectangle | true
): Rectangle;

getBoundaryPoints(
tileXYArray?: ChessType[] | TileXYType[],
out?: WorldXYType[]
): WorldXYType[];

getBoundaryPoints(
tileZ?: number | string,
out?: WorldXYType[]
): WorldXYType[];

chessToBoard(chess: any): Board;
static GetBoard(chess: any): Board;

Expand Down

0 comments on commit e3fcd92

Please sign in to comment.