Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. /* Babylon Scene Controller Template */
  2.  
  3. module PROJECT {
  4. var AdvancedTexture;
  5. var phoneText, targetText, scoreText: BABYLON.GUI.TextBlock;
  6. var OrientationX, OrientationY, OrientationZ;
  7. var MotionX, MotionY, MotionZ;
  8. var targetVector3: BABYLON.Vector3;
  9.  
  10. export class GameMesterComponent extends BABYLON.MeshComponent {
  11. public constructor(owner: BABYLON.AbstractMesh, scene: BABYLON.Scene, tick: boolean = true, propertyBag: any = {}) {
  12. super(owner, scene, tick, propertyBag);
  13. }
  14.  
  15. protected ready(): void {
  16. // Scene execute when ready
  17. }
  18.  
  19. protected start(): void {
  20. // Start component function
  21.  
  22.  
  23. // GUI
  24. this.createGUI();
  25. this.deviceMotion();
  26.  
  27. targetVector3 = new BABYLON.Vector3(64, 50, 90);
  28. targetText.text = targetVector3.toString();
  29. }
  30.  
  31. protected update(): void {
  32. // Update render loop function
  33. phoneText.text = "陀螺儀 = X:" + OrientationX + " Y:" + OrientationY + " Z:" + OrientationZ + '\n' + "加速器 = X:" + MotionX + " Y:" + MotionY + " Z:" + MotionZ;
  34.  
  35. if (Math.abs(OrientationX - targetVector3.x) < 10 &&
  36. Math.abs(OrientationY - targetVector3.y) < 10 &&
  37. Math.abs(OrientationZ - targetVector3.z) < 10) {
  38. scoreText.text = "好棒棒";
  39. }
  40.  
  41. }
  42.  
  43. protected after(): void {
  44. // After render loop function
  45. }
  46.  
  47. protected destroy(): void {
  48. // Destroy component function
  49. }
  50.  
  51. protected createGUI(): void {
  52. AdvancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("myUI");
  53. phoneText = new BABYLON.GUI.TextBlock();
  54. phoneText.color = "white";
  55. phoneText.fontSize = 64;
  56. phoneText.resizeToFit = true;
  57. phoneText.outlineWidth = 5;
  58. phoneText.outlineColor = "black";
  59. phoneText.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  60. phoneText.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  61. phoneText.paddingBottom = 350;
  62. AdvancedTexture.addControl(phoneText);
  63.  
  64.  
  65. targetText = new BABYLON.GUI.TextBlock();
  66. targetText.color = "white";
  67. targetText.fontSize = 64;
  68. targetText.resizeToFit = true;
  69. targetText.outlineWidth = 5;
  70. targetText.outlineColor = "green";
  71. targetText.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  72. targetText.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  73. AdvancedTexture.addControl(targetText);
  74.  
  75. targetText.text = "hello";
  76.  
  77. scoreText = new BABYLON.GUI.TextBlock();
  78. scoreText.color = "white";
  79. scoreText.fontSize = 64;
  80. scoreText.resizeToFit = true;
  81. scoreText.outlineWidth = 5;
  82. scoreText.outlineColor = "red";
  83. scoreText.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
  84. scoreText.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
  85. scoreText.paddingBottom = 150;
  86. AdvancedTexture.addControl(scoreText);
  87.  
  88. scoreText.text = "0";
  89. }
  90.  
  91. protected deviceMotion(): void {
  92. window.addEventListener("deviceorientation", function (event) {
  93. OrientationX = Math.round(event.beta);
  94. OrientationY = Math.round(event.gamma);
  95. OrientationZ = Math.round(event.alpha);
  96. }, true);
  97.  
  98.  
  99. window.addEventListener("devicemotion", function (event) {
  100. MotionX = Math.round(event.acceleration.x);
  101. MotionY = Math.round(event.acceleration.y);
  102. MotionZ = Math.round(event.acceleration.z);
  103. }, true);
  104.  
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement