简体   繁体   English

如何在一个场景中改变重力(Phaser)?

[英]How to change gravity just in one scene (Phaser)?

I would like to learn making games using Phaser.我想学习使用 Phaser 制作游戏。

I know you define the gravity in the config, like this:我知道您在配置中定义了重力,如下所示:

var config = {
        type: Phaser.AUTO,
        width: 800,
        height: 600,
        physics: {
            default: 'arcade',
            arcade: {
                gravity: { y: 300 },
                debug: false
            }
        },
        scene: [FirstScene, SecondScene,...]
    };

But this applies to all scenes.但这适用于所有场景。 Is there a way how to change the gravity in just one scene.有没有办法在一个场景中改变重力。

You can specify the gravity for a particular scene by redefining the physics settings in the scene's constructor method.您可以通过在场景的构造方法中重新定义物理设置来指定特定场景的重力。

class FirstScene extends Phaser.Scene {
  constructor() {
    super({
      key: 'first',
      physics: {
        default: 'arcade',
        arcade: { 
          gravity: { y: 2000 }
        }
      }
    });
} 

Check out the API Docs to see what else can be configured on a scene-by-scene basis.查看 API 文档,了解可以逐个场景配置的其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM