Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 相位器3中的旋转约束_Javascript_Phaser Framework_Game Development_Revolute Joints - Fatal编程技术网

Javascript 相位器3中的旋转约束

Javascript 相位器3中的旋转约束,javascript,phaser-framework,game-development,revolute-joints,Javascript,Phaser Framework,Game Development,Revolute Joints,我对phaser是新手,正在努力学习phaser 3。 我需要一个项目的旋转约束 有使用box2d和p2physics的phaser 2示例,但它们在phaser 3中不起作用 我试着在文档中查找,但我认为它还不完整 任何人都可以告诉我如何在phaser 3中创建旋转约束(或销接头)。检查此示例并点击运行代码按钮: 在此处签出示例并点击运行代码按钮: var config = { type: Phaser.AUTO, width: 800, height: 600,

我对phaser是新手,正在努力学习phaser 3。 我需要一个项目的旋转约束

有使用box2d和p2physics的phaser 2示例,但它们在phaser 3中不起作用

我试着在文档中查找,但我认为它还不完整


任何人都可以告诉我如何在phaser 3中创建旋转约束(或销接头)。

检查此示例并点击运行代码按钮:


在此处签出示例并点击运行代码按钮:

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    backgroundColor: '#1b1464',
    parent: 'phaser-example',
    physics: {
        default: 'matter'
    },
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('ball', 'assets/sprites/shinyball.png');
}

function create ()
{
    this.matter.world.setBounds();

    //  Our two bodies which will be connected by a constraint (aka a Joint or a Spring)

    var ballA = this.matter.add.image(420, 100, 'ball', null, { shape: 'circle', friction: 0.005, restitution: 0.6 });
    var ballB = this.matter.add.image(400, 200, 'ball', null, { shape: 'circle', friction: 0.005, restitution: 0.6 });

    //  You can create a constraint between the two bodies using a Factory function.
    //  The value 100 is the resting length and 0.2 is the stiffness of the constraint.

    this.matter.add.constraint(ballA, ballB, 100, 0.2);

    //  To help those of you more used to the Box2D syntax you can use
    //  add.joint or add.spring instead (with the exact same parameters)

    // this.matter.add.spring(ballA, ballB, 100, 0.2);
    // this.matter.add.joint(ballA, ballB, 100, 0.2);

    //  Or you can create a native Matter constraint:

    // var constraint = Phaser.Physics.Matter.Matter.Constraint.create({
    //     bodyA: ballA.body,
    //     bodyB: ballB.body,
    //     length: 100,
    //     stiffness: 0.2
    // });

    //  Which you then have to add to the world yourself:

    // this.matter.world.add(constraint);

    this.matter.add.mouseSpring();
}