PlunkerでPhaser.Physics その13

# 概要
Plunkerで、Phaser.Physicsやってみた。
motorJoint、使ってみた。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/6e5a9e41-c1ac-d166-f535-32d02a95388a.png)


# サンプルコード

```

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { 
    preload: preload, 
    create: create, 
    update: update, 
    render: render 
});
function preload() {
    game.load.image('a', 'assets/sprites/a.png');
    game.load.image('b', 'assets/sprites/b.png');
}
var codeCaption;
var bodyAs = [];
function create() {
    game.stage.backgroundColor = '#124184';
    game.physics.startSystem(Phaser.Physics.BOX2D);
    game.physics.box2d.debugDraw.joints = true;
    game.physics.box2d.setBoundsToWorld();
    game.physics.box2d.gravity.y = 500;
    {
        var spriteA = game.add.sprite(200, 200, 'a');
        game.physics.box2d.enable(spriteA);
        spriteA.body.static = true;
        var spriteB = game.add.sprite(200, 200, 'b');
        game.physics.box2d.enable(spriteB);
        game.physics.box2d.motorJoint(spriteA, spriteB, 100, 0, 0.5);
        bodyAs.push(spriteA.body);
    }
    {
        var spriteA = game.add.sprite(600, 200, 'a');
        game.physics.box2d.enable(spriteA);
        spriteA.body.static = true;
        var spriteB = game.add.sprite(600, 200, 'b');
        game.physics.box2d.enable(spriteB);
        game.physics.box2d.motorJoint(spriteA, spriteB, 0, 50, 0.5);
        bodyAs.push(spriteA.body);
    }
    {
        var spriteA = game.add.sprite(200, 400, 'a');
        game.physics.box2d.enable(spriteA);
        spriteA.body.static = true;
        var spriteB = game.add.sprite(200, 400, 'b');
        game.physics.box2d.enable(spriteB);
        game.physics.box2d.motorJoint(spriteA, spriteB, 100, 50, 0.5);
        bodyAs.push(spriteA.body);
    }
    {
        var spriteA = game.add.sprite(600, 400, 'a');
        game.physics.box2d.enable(spriteA);
        spriteA.body.static = true;
        var spriteB = game.add.sprite(600, 400, 'b');
        game.physics.box2d.enable(spriteB);
        var j = game.physics.box2d.motorJoint(spriteA, spriteB, 100, 50, 0.5, -50, 60, 30);
        bodyAs.push(spriteA.body);
    }
    game.input.onDown.add(mouseDragStart, this);
    game.input.addMoveCallback(mouseDragMove, this);
    game.input.onUp.add(mouseDragEnd, this);
    game.add.text(5, 5, 'Motor joint. Click to start.', { 
        fill: '#ffffff', 
        font: '14pt Arial' 
    });
    game.add.text(5, 25, 'Mouse over bodyA to see the code used to create the joint.', { 
        fill: '#ffffff', 
        font: '14pt Arial' 
    });
    codeCaption = game.add.text(5, 50, 'Parameters: bodyA, bodyB, maxForce, maxTorque, ax, ay, bx, by', { 
        fill: '#dddddd', 
        font: '10pt Arial' 
    });
    codeCaption = game.add.text(5, 65, '', { 
        fill: '#ccffcc', 
        font: '14pt Arial' 
    });
    game.paused = true;
    game.input.onDown.add(function() {
        game.paused = false;
    }, this);
}
function mouseDragStart() { 
    game.physics.box2d.mouseDragStart(game.input.mousePointer); 
}
function mouseDragMove() {  
    game.physics.box2d.mouseDragMove(game.input.mousePointer); 
}
function mouseDragEnd() {   
    game.physics.box2d.mouseDragEnd(); 
}
function update() {
    if (bodyAs[0].containsPoint(game.input.mousePointer))
    {
        codeCaption.text = 'game.physics.box2d.motorJoint(spriteA, spriteB, 50, 0)';
    }
    else if (bodyAs[1].containsPoint(game.input.mousePointer))
    {
        codeCaption.text = 'game.physics.box2d.motorJoint(spriteA, spriteB, 0, 50)';
    }
    else if (bodyAs[2].containsPoint(game.input.mousePointer))
    {
        codeCaption.text = 'game.physics.box2d.motorJoint(spriteA, spriteB, 50, 50)';
    }
    else if (bodyAs[3].containsPoint(game.input.mousePointer))
    {
        codeCaption.text = 'game.physics.box2d.motorJoint(spriteA, spriteB, 50, 50, 0, 0, 100, 0)';
    }
    else
    {
        codeCaption.text = '';
    }
}
function render() {
    if (game.paused)
    {
        update();
    }
    game.debug.box2dWorld();
}




```

# 成果物

https://embed.plnkr.co/plunk/lvuQSIyABCF6mXhC


以上。