JAVASCRIPT   11

vertices body.js

Guest on 30th May 2021 09:52:59 PM

  1. var config = {
  2.     type: Phaser.AUTO,
  3.     width: 800,
  4.     height: 600,
  5.     backgroundColor: '#efefef',
  6.     parent: 'phaser-example',
  7.     physics: {
  8.         default: 'matter',
  9.         matter: {
  10.             debug: {
  11.                 renderFill: false,
  12.                 showInternalEdges: true,
  13.                 showConvexHulls: true
  14.             }
  15.         }
  16.     },
  17.     scene: {
  18.         create: create
  19.     }
  20. };
  21.  
  22. var game = new Phaser.Game(config);
  23.  
  24. function create ()
  25. {
  26.     this.matter.world.setBounds().disableGravity();
  27.  
  28.     var arrow = '40 0 40 20 100 20 100 80 40 80 40 100 0 50';
  29.     var chevron = '100 0 75 50 100 100 25 100 0 50 25 0';
  30.     var star = '50 0 63 38 100 38 69 59 82 100 50 75 18 100 31 59 0 38 37 38';
  31.  
  32.     var poly = this.add.polygon(400, 300, arrow, 0x0000ff, 0.2);
  33.  
  34.     this.matter.add.gameObject(poly, { shape: { type: 'fromVerts', verts: arrow, flagInternal: true } });
  35.  
  36.     poly.setVelocity(6, 3);
  37.     poly.setAngularVelocity(0.01);
  38.     poly.setBounce(1);
  39.     poly.setFriction(0, 0, 0);
  40.  
  41.     var poly = this.add.polygon(400, 100, chevron, 0xff0000, 0.2);
  42.  
  43.     this.matter.add.gameObject(poly, { shape: { type: 'fromVerts', verts: chevron, flagInternal: true } });
  44.  
  45.     poly.setVelocity(6, 3);
  46.     poly.setAngularVelocity(0.01);
  47.     poly.setBounce(1);
  48.     poly.setFriction(0, 0, 0);
  49.  
  50.     var poly = this.add.polygon(600, 400, star, 0x00ff00, 0.2);
  51.  
  52.     this.matter.add.gameObject(poly, { shape: { type: 'fromVerts', verts: star, flagInternal: true } });
  53.  
  54.     poly.setVelocity(4, -2);
  55.     poly.setBounce(1);
  56.     poly.setFriction(0, 0, 0);
  57.     poly.setFrictionAir(0.005);
  58. }

Raw Paste


Login or Register to edit or fork this paste. It's free.