Проверить Matter.js
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

73 satır
3.0KB

  1. function РучноеТело() {
  2. this.настроить = function()
  3. {
  4. if (this.настроено)
  5. {
  6. return;
  7. }
  8. this.настроено = true;
  9. // 1.
  10. this.тело1 = Matter.Bodies.rectangle(125, 300, 40, 40, { isSensor: true });
  11. this.элемент1 = document.createElement("div");
  12. document.getElementById("корень").appendChild(this.элемент1);
  13. this.элемент1.style.position = "absolute";
  14. this.элемент1.style.display = "block";
  15. this.элемент1.style.transformOrigin = "center";
  16. this.элемент1.style.width = `40px`;
  17. this.элемент1.style.height = `40px`;
  18. this.элемент1.style.setProperty("background", "url(р/отладка/основа.jpg)");
  19. this.элемент1.style.setProperty("z-index", "100");
  20. // 2.
  21. this.тело2 = Matter.Bodies.rectangle(55, 300, 40, 40, { inertia: Infinity });
  22. this.элемент2 = document.createElement("div");
  23. document.getElementById("корень").appendChild(this.элемент2);
  24. this.элемент2.style.position = "absolute";
  25. this.элемент2.style.display = "block";
  26. this.элемент2.style.transformOrigin = "center";
  27. this.элемент2.style.width = `40px`;
  28. this.элемент2.style.height = `40px`;
  29. this.элемент2.style.setProperty("background", "url(р/отладка/основа.jpg)");
  30. this.элемент2.style.setProperty("z-index", "100");
  31. /*
  32. Matter.Composite.add(мир.физика.движок.world, this.тело1);
  33. Matter.Composite.add(мир.физика.движок.world, this.тело2);
  34. мир.объекты.тела["рт"] = this.тело2;
  35. this.тело = this.тело2;
  36. */
  37. // Compound.
  38. this.тело = Matter.Body.create({
  39. parts: [this.тело1, this.тело2],
  40. inertia: Infinity,
  41. });
  42. Matter.Composite.add(мир.физика.движок.world, this.тело);
  43. мир.объекты.тела["рт"] = this.тело;
  44. мир.объекты.тела["рт1"] = this.тело1;
  45. мир.объекты.имена[this.тело1.id] = "рт1";
  46. мир.объекты.тела["рт2"] = this.тело2;
  47. мир.объекты.имена[this.тело2.id] = "рт2";
  48. };
  49. this.обновить = function()
  50. {
  51. this.настроить();
  52. if (!this.тело)
  53. {
  54. return;
  55. }
  56. мир.синхронизироватьЭлементТело(this.элемент1, this.тело1);
  57. мир.синхронизироватьЭлементТело(this.элемент2, this.тело2);
  58. };
  59. this.отладить = function()
  60. {
  61. console.debug("РТ.отладить. позиции тело/тело1/тело2:", this.тело.position, this.тело1.position, this.тело2.position);
  62. };
  63. }