修改多边形生成
This commit is contained in:
@@ -121,60 +121,90 @@ class layout {
|
||||
y: 683
|
||||
});
|
||||
|
||||
console.log(pusher)
|
||||
// console.log(pusher)
|
||||
|
||||
gsap.to(pusher, { y: '-=202', yoyo: true, repeat: -1, ease: 'none', duration: 5 })
|
||||
|
||||
// 添加到
|
||||
this.gamePage.addChild(bottom, pusher, top);
|
||||
// 添加ground
|
||||
this.game.Composite.add(this.game.myWorld, [
|
||||
this.game.Bodies.fromVertices(
|
||||
window.innerWidth / 2, window.innerHeight / 2,
|
||||
[
|
||||
// 顶点坐标
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 0, y: 956 },
|
||||
{ x: 141, y: 881 },
|
||||
{ x: 206, y: 683 },
|
||||
{ x: 548, y: 683 },
|
||||
{ x: 614, y: 881 },
|
||||
{ x: 750, y: 956 },
|
||||
{ x: 750, y: 0 }
|
||||
],
|
||||
// { isStatic: true }
|
||||
)
|
||||
]);
|
||||
|
||||
|
||||
// Create a concave polygon
|
||||
var _g = [
|
||||
// 顶点坐标
|
||||
{ x: 0, y: 0 },
|
||||
{ x: 0, y: 956 },
|
||||
{ x: 141, y: 881 },
|
||||
{ x: 206, y: 683 },
|
||||
{ x: 548, y: 683 },
|
||||
{ x: 614, y: 881 },
|
||||
{ x: 750, y: 956 },
|
||||
{ x: 750, y: 0 },
|
||||
];
|
||||
var concavePolygon = [
|
||||
[-1, 1],
|
||||
[-1, 0],
|
||||
[1, 0],
|
||||
[1, 1],
|
||||
[0.5, 0.5]
|
||||
// 顶点坐标
|
||||
[0, 0],
|
||||
[0, 956],
|
||||
[141, 881],
|
||||
[206, 683],
|
||||
[548, 683],
|
||||
[614, 881],
|
||||
[750, 956],
|
||||
[750, 0],
|
||||
];
|
||||
|
||||
// Make sure the polygon has counter-clockwise winding. Skip this step if you know it's already counter-clockwise.
|
||||
decomp.makeCCW(concavePolygon);
|
||||
|
||||
// Decompose into convex polygons, using the faster algorithm
|
||||
var convexPolygons = decomp.quickDecomp(concavePolygon);
|
||||
|
||||
var convexPolygons = decomp.quickDecomp(concavePolygon);
|
||||
// ==> [ [[1,0],[1,1],[0.5,0.5]], [[0.5,0.5],[-1,1],[-1,0],[1,0]] ]
|
||||
|
||||
// Decompose using the slow (but optimal) algorithm
|
||||
var convexPolygons = decomp.decomp(concavePolygon);
|
||||
// // Decompose using the slow (but optimal) algorithm
|
||||
// var convexPolygons = decomp.decomp(concavePolygon);
|
||||
|
||||
convexPolygons.forEach((item) => {
|
||||
item.forEach((t, i) => {
|
||||
item.push({
|
||||
x: t[0],
|
||||
y: t[1]
|
||||
})
|
||||
if (i == (item.length / 2) - 1) {
|
||||
item.splice(0, item.length / 2)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
console.log(convexPolygons)
|
||||
// 添加ground
|
||||
this.game.Composite.add(this.game.myWorld,
|
||||
this.game.Bodies.fromVertices(
|
||||
window.innerWidth / 2, window.innerHeight / 2,
|
||||
convexPolygons,
|
||||
{
|
||||
isStatic: true,
|
||||
scale: {
|
||||
screenX: 0.5,
|
||||
screenY: 0.5,
|
||||
},
|
||||
render: {
|
||||
fillStyle: 'rgba(39,7,238,0.25)'
|
||||
}
|
||||
},
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
//
|
||||
let bounds = pusher.getBounds();
|
||||
pusher.body = this.game.Bodies.trapezoid(
|
||||
pusher.x,
|
||||
pusher.y,
|
||||
bounds.width,
|
||||
bounds.height,
|
||||
{ isStatic: true }
|
||||
);
|
||||
// let bounds = pusher.getBounds();
|
||||
// pusher.body = this.game.Bodies.trapezoid(
|
||||
// pusher.x,
|
||||
// pusher.y,
|
||||
// bounds.width,
|
||||
// bounds.height,
|
||||
// 1,
|
||||
// { isStatic: true }
|
||||
// );
|
||||
// this.game.Composite.add(this.myWorld, [pusher.body]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user