Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Babylon Scene Controller Template */
- module PROJECT {
- var AdvancedTexture;
- var phoneText, targetText, scoreText: BABYLON.GUI.TextBlock;
- var OrientationX, OrientationY, OrientationZ;
- var MotionX, MotionY, MotionZ;
- var targetVector3: BABYLON.Vector3;
- export class GameMesterComponent extends BABYLON.MeshComponent {
- public constructor(owner: BABYLON.AbstractMesh, scene: BABYLON.Scene, tick: boolean = true, propertyBag: any = {}) {
- super(owner, scene, tick, propertyBag);
- }
- protected ready(): void {
- // Scene execute when ready
- }
- protected start(): void {
- // Start component function
- // GUI
- this.createGUI();
- this.deviceMotion();
- targetVector3 = new BABYLON.Vector3(64, 50, 90);
- targetText.text = targetVector3.toString();
- }
- protected update(): void {
- // Update render loop function
- phoneText.text = "陀螺儀 = X:" + OrientationX + " Y:" + OrientationY + " Z:" + OrientationZ + '\n' + "加速器 = X:" + MotionX + " Y:" + MotionY + " Z:" + MotionZ;
- if (Math.abs(OrientationX - targetVector3.x) < 10 &&
- Math.abs(OrientationY - targetVector3.y) < 10 &&
- Math.abs(OrientationZ - targetVector3.z) < 10) {
- scoreText.text = "好棒棒";
- }
- }
- protected after(): void {
- // After render loop function
- }
- protected destroy(): void {
- // Destroy component function
- }
- protected createGUI(): void {
- AdvancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI("myUI");
- phoneText = new BABYLON.GUI.TextBlock();
- phoneText.color = "white";
- phoneText.fontSize = 64;
- phoneText.resizeToFit = true;
- phoneText.outlineWidth = 5;
- phoneText.outlineColor = "black";
- phoneText.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
- phoneText.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
- phoneText.paddingBottom = 350;
- AdvancedTexture.addControl(phoneText);
- targetText = new BABYLON.GUI.TextBlock();
- targetText.color = "white";
- targetText.fontSize = 64;
- targetText.resizeToFit = true;
- targetText.outlineWidth = 5;
- targetText.outlineColor = "green";
- targetText.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
- targetText.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
- AdvancedTexture.addControl(targetText);
- targetText.text = "hello";
- scoreText = new BABYLON.GUI.TextBlock();
- scoreText.color = "white";
- scoreText.fontSize = 64;
- scoreText.resizeToFit = true;
- scoreText.outlineWidth = 5;
- scoreText.outlineColor = "red";
- scoreText.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
- scoreText.verticalAlignment = BABYLON.GUI.Control.VERTICAL_ALIGNMENT_CENTER;
- scoreText.paddingBottom = 150;
- AdvancedTexture.addControl(scoreText);
- scoreText.text = "0";
- }
- protected deviceMotion(): void {
- window.addEventListener("deviceorientation", function (event) {
- OrientationX = Math.round(event.beta);
- OrientationY = Math.round(event.gamma);
- OrientationZ = Math.round(event.alpha);
- }, true);
- window.addEventListener("devicemotion", function (event) {
- MotionX = Math.round(event.acceleration.x);
- MotionY = Math.round(event.acceleration.y);
- MotionZ = Math.round(event.acceleration.z);
- }, true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement