修改多边形生成
This commit is contained in:
parent
dad2d7a12d
commit
8507d848b4
@ -44,6 +44,7 @@ class game {
|
|||||||
this.utils = utils;
|
this.utils = utils;
|
||||||
|
|
||||||
// init Matter
|
// init Matter
|
||||||
|
this.Matter = Matter;
|
||||||
this.Engine = Matter.Engine,
|
this.Engine = Matter.Engine,
|
||||||
this.Render = Matter.Render,
|
this.Render = Matter.Render,
|
||||||
this.Runner = Matter.Runner,
|
this.Runner = Matter.Runner,
|
||||||
@ -193,7 +194,7 @@ class game {
|
|||||||
initMatterEngine() {
|
initMatterEngine() {
|
||||||
// create an engine
|
// create an engine
|
||||||
this.myEngine = this.Engine.create();
|
this.myEngine = this.Engine.create();
|
||||||
this.myEngine.gravity.y = 0.1;
|
this.myEngine.gravity.y = 0;
|
||||||
this.myWorld = this.myEngine.world;
|
this.myWorld = this.myEngine.world;
|
||||||
|
|
||||||
|
|
||||||
@ -203,13 +204,13 @@ class game {
|
|||||||
engine: this.myEngine,
|
engine: this.myEngine,
|
||||||
canvas: this.vue.$refs.matter,
|
canvas: this.vue.$refs.matter,
|
||||||
options: {
|
options: {
|
||||||
width: window.innerWidth,
|
width: 375, //window.innerWidth,
|
||||||
height: window.innerHeight,
|
height: 812, //window.innerHeight,
|
||||||
pixelRatio: window.devicePixelRatio, // 设置像素比
|
pixelRatio: 1, // 设置像素比 window.devicePixelRatio
|
||||||
background: 'transparent',
|
background: 'transparent',
|
||||||
wireframeBackground: "transparent",
|
wireframeBackground: "transparent",
|
||||||
showAngleIndicator: false,
|
showAngleIndicator: false,
|
||||||
wireframes: true,
|
wireframes: false,
|
||||||
showDebug: false,
|
showDebug: false,
|
||||||
showVelocity: true,
|
showVelocity: true,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,17 +121,16 @@ class layout {
|
|||||||
y: 683
|
y: 683
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(pusher)
|
// console.log(pusher)
|
||||||
|
|
||||||
gsap.to(pusher, { y: '-=202', yoyo: true, repeat: -1, ease: 'none', duration: 5 })
|
gsap.to(pusher, { y: '-=202', yoyo: true, repeat: -1, ease: 'none', duration: 5 })
|
||||||
|
|
||||||
// 添加到
|
// 添加到
|
||||||
this.gamePage.addChild(bottom, pusher, top);
|
this.gamePage.addChild(bottom, pusher, top);
|
||||||
// 添加ground
|
|
||||||
this.game.Composite.add(this.game.myWorld, [
|
|
||||||
this.game.Bodies.fromVertices(
|
// Create a concave polygon
|
||||||
window.innerWidth / 2, window.innerHeight / 2,
|
var _g = [
|
||||||
[
|
|
||||||
// 顶点坐标
|
// 顶点坐标
|
||||||
{ x: 0, y: 0 },
|
{ x: 0, y: 0 },
|
||||||
{ x: 0, y: 956 },
|
{ x: 0, y: 956 },
|
||||||
@ -140,41 +139,72 @@ class layout {
|
|||||||
{ x: 548, y: 683 },
|
{ x: 548, y: 683 },
|
||||||
{ x: 614, y: 881 },
|
{ x: 614, y: 881 },
|
||||||
{ x: 750, y: 956 },
|
{ x: 750, y: 956 },
|
||||||
{ x: 750, y: 0 }
|
{ x: 750, y: 0 },
|
||||||
],
|
];
|
||||||
// { isStatic: true }
|
|
||||||
)
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Create a concave polygon
|
|
||||||
var concavePolygon = [
|
var concavePolygon = [
|
||||||
[-1, 1],
|
// 顶点坐标
|
||||||
[-1, 0],
|
[0, 0],
|
||||||
[1, 0],
|
[0, 956],
|
||||||
[1, 1],
|
[141, 881],
|
||||||
[0.5, 0.5]
|
[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.
|
// Make sure the polygon has counter-clockwise winding. Skip this step if you know it's already counter-clockwise.
|
||||||
decomp.makeCCW(concavePolygon);
|
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]] ]
|
// ==> [ [[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
|
// // Decompose using the slow (but optimal) algorithm
|
||||||
var convexPolygons = decomp.decomp(concavePolygon);
|
// 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();
|
// let bounds = pusher.getBounds();
|
||||||
pusher.body = this.game.Bodies.trapezoid(
|
// pusher.body = this.game.Bodies.trapezoid(
|
||||||
pusher.x,
|
// pusher.x,
|
||||||
pusher.y,
|
// pusher.y,
|
||||||
bounds.width,
|
// bounds.width,
|
||||||
bounds.height,
|
// bounds.height,
|
||||||
{ isStatic: true }
|
// 1,
|
||||||
);
|
// { isStatic: true }
|
||||||
|
// );
|
||||||
// this.game.Composite.add(this.myWorld, [pusher.body]);
|
// this.game.Composite.add(this.myWorld, [pusher.body]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -36,13 +36,13 @@ export default {
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||||
<style scoped lang="less">
|
<style lang="less">
|
||||||
.pushcoin {
|
.pushcoin {
|
||||||
.prLayout(100%,100%);
|
.prLayout(100%,100%);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: #333;
|
background-color: #333;
|
||||||
.matter {
|
.matter {
|
||||||
.paLayout(0,0,750px,1624px,1);
|
.paPos(0,0,1);
|
||||||
}
|
}
|
||||||
#stageCanvas {
|
#stageCanvas {
|
||||||
.paLayout(0,0,750px,1624px,0);
|
.paLayout(0,0,750px,1624px,0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user