Browse Source

menu button

unknown 2 năm trước cách đây
mục cha
commit
ebf23292a5
3 tập tin đã thay đổi với 32 bổ sung8 xóa
  1. 1 2
      package.json
  2. 16 0
      src/Scenes/HelloWorldScene.ts
  3. 15 6
      src/Scenes/LevelTwo.ts

+ 1 - 2
package.json

@@ -10,8 +10,7 @@
 		"predeploy": "npm run build",
 		"deploy": "gh-pages -d dist",
 		"preview": "vite preview"
-		},
-		
+	},
 	"devDependencies": {
 		"@typescript-eslint/eslint-plugin": "^5.40.0",
 		"@typescript-eslint/parser": "^5.40.0",

+ 16 - 0
src/Scenes/HelloWorldScene.ts

@@ -6,6 +6,8 @@ import Button from '../Objects/Button';
 import Player  from '../Objects/Player';
 //import Player from "./Objects/Player";
 
+import { TextButtonObject } from "../Objects/TextButtonObject";
+
 
 export default class HelloWorldScene extends Phaser.Scene {
     //Sprite creation
@@ -24,6 +26,8 @@ export default class HelloWorldScene extends Phaser.Scene {
     private nextScene?: Phaser.GameObjects.Text;
     //reset
     private resetText: Phaser.GameObjects.Text | undefined;
+    //menuText
+    private menuText: Phaser.GameObjects.Text | undefined;
 
     constructor() {
         super('HelloWorldScene')
@@ -223,6 +227,18 @@ export default class HelloWorldScene extends Phaser.Scene {
         this.resetText.on('pointerdown', () => {
             this.scene.restart();
         });
+
+        // back to main
+        this.menuText = this.add.text(40, 10, 'Menu', { fontFamily: 'Arial', fontSize: '32', color: '#ffffff' });
+        // menu Text touchable
+        this.menuText.setInteractive();
+        // menuText
+        this.menuText.on('pointerdown', () => {
+            this.scene.start('BaseScene');
+        });
+        
+        
+
     }
 
     //Handle buttons

+ 15 - 6
src/Scenes/LevelTwo.ts

@@ -5,6 +5,8 @@ import Button from '../Objects/Button';
 import Player  from '../Objects/Player';
 //import Player from "./Objects/Player";
 
+import { TextButtonObject } from "../Objects/TextButtonObject";
+
 
 export default class LevelTwo extends Phaser.Scene {
     //Sprite creation
@@ -23,6 +25,8 @@ export default class LevelTwo extends Phaser.Scene {
     private nextScene?: Phaser.GameObjects.Text;
     //reset
     private resetText: Phaser.GameObjects.Text | undefined;
+    //menuText
+    private menuText: Phaser.GameObjects.Text | undefined;
 
     constructor() {
         super('LevelTwo')
@@ -230,12 +234,15 @@ export default class LevelTwo extends Phaser.Scene {
         this.physics.add.collider(this.buttons, this.platforms)
         this.physics.add.overlap(this.player1, this.buttons, this.handleHitButton, undefined, this)
         this.physics.add.overlap(this.player2, this.buttons, this.handleHitButton, undefined, this)
-        // reset touchable
-        this.resetText.setInteractive();
-        // monitor reset
-        this.resetText.on('pointerdown', () => {
-          this.scene.restart();
-        }); 
+        
+        // back to main
+        this.menuText = this.add.text(40, 10, 'Menu', { fontFamily: 'Arial', fontSize: '32', color: '#ffffff' });
+        // menu Text touchable
+        this.menuText.setInteractive();
+        // menuText
+        this.menuText.on('pointerdown', () => {
+            this.scene.start('BaseScene');
+        });
     }
 
     //Handle buttons
@@ -262,10 +269,12 @@ export default class LevelTwo extends Phaser.Scene {
         return;
     }
 
+
 	// sence transition
     private handleLoadNextScene() {
         this.scene.start('EndScene')
     }
+    
 	//ThreeScene
 	//private handleLoadNextScene(player1: Phaser.GameObjects.GameObject, sA: Phaser.GameObjects.GameObject) {
         //this.scene.start('ThreeScene')