feat: convex hull for layer geometry
This commit is contained in:
parent
acb7b41e41
commit
fca289642b
|
@ -4,6 +4,7 @@ import {compose} from '@avocado/core';
|
|||
import {create as createEntity, EntityList} from '@avocado/entity';
|
||||
import {Vector} from '@avocado/math';
|
||||
import {EventEmitter, Property} from '@avocado/mixins';
|
||||
import {ShapeList} from '@avocado/physics';
|
||||
import {Synchronized} from '@avocado/state';
|
||||
|
||||
import {Tiles} from './tiles';
|
||||
|
@ -53,20 +54,22 @@ export class Layer extends decorate(Synchronized) {
|
|||
return false;
|
||||
}
|
||||
const halfTileSize = Vector.scale(tileset.tileSize, 0.5);
|
||||
const shapeList = new ShapeList()
|
||||
this.tiles.forEachTile((tile, x, y, i) => {
|
||||
const shape = this.tileset.geometry(tile);
|
||||
if (!shape) {
|
||||
return;
|
||||
}
|
||||
const body = world.createBody(shape);
|
||||
body.position = Vector.add(
|
||||
shape.position = Vector.add(
|
||||
halfTileSize,
|
||||
Vector.mul([x, y], tileset.tileSize),
|
||||
);
|
||||
body.static = true;
|
||||
world.addBody(body);
|
||||
this.tileGeometry.push(body);
|
||||
shapeList.addShape(shape);
|
||||
});
|
||||
const body = world.createBody(shapeList);
|
||||
body.static = true;
|
||||
world.addBody(body);
|
||||
this.tileGeometry.push(body);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user