Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. export default class Obj {
  2. constructor(scene, index, polygon) {
  3. this.scene = scene;
  4. this.index = index;
  5. this.polygon = polygon;
  6. this.bbox = polygon.aabb();
  7. this.sprite = scene.matter.add.sprite(0, 0, "obj_"+index, 0);
  8.  
  9.  
  10. const { Body, Bodies } = Phaser.Physics.Matter.Matter;
  11.  
  12. const objBody = Bodies.fromVertices(this.polygon.center().x,this.polygon.center().y,polygon.points);
  13.  
  14. this.sprite
  15. .setExistingBody(objBody)
  16. .setFixedRotation() // Sets inertia to infinity so the player can't rotate
  17. .setStatic(true)
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement