概要
Plunkerで、Phaser.Physicsやってみた。
写真
サンプルコード
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', {
preload: preload,
create: create,
render: render
});
function preload() {
//game.load.image('ball', 'assets/sprites/shinyball.png');
}
var circle
function create() {
game.stage.backgroundColor = '#124184';
game.physics.startSystem(Phaser.Physics.BOX2D);
game.physics.box2d.gravity.y = 500;
game.physics.box2d.restitution = 0.8;
game.physics.box2d.setBoundsToWorld();
var ball = game.add.sprite(400, game.world.centerY, 'ball');
game.physics.box2d.enable(ball);
ball.body.setCircle(ball.width / 2);
var circle = game.physics.box2d.createCircle(300, 300, 32);
var square1 = new Phaser.Physics.Box2D.Body(this.game, null, 200, 130, 2);
square1.setRectangle(50, 50, 0, 0, 0);
square1.friction = 0.4;
}
function render() {
game.debug.box2dWorld();
}
成果物
以上。