mirror of
https://github.com/wassname/phaser.git
synced 2026-09-10 12:29:30 +08:00
Body.loadPolygon now parses all shapes that may exist in a JSON data file, and re-creates them all on the Body. Assumes shapes are CCW + Convex (tested working with Lime Exportor). Almost fixes #449 but Body rotation seems to screw orientation of shapes.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('contra2', 'assets/pics/contra2.png');
|
||||
game.load.image('bunny', 'assets/sprites/bunny.png');
|
||||
game.load.image('tetrisblock1', 'assets/sprites/tetrisblock1.png');
|
||||
game.load.image('tetrisblock2', 'assets/sprites/tetrisblock2.png');
|
||||
game.load.image('tetrisblock3', 'assets/sprites/tetrisblock3.png');
|
||||
|
||||
// Load our physcs data exported from PhysicsEditor
|
||||
game.load.physics('physicsData', 'assets/physics/sprites.json');
|
||||
|
||||
}
|
||||
|
||||
var contra;
|
||||
var start = false;
|
||||
|
||||
function create() {
|
||||
|
||||
contra = game.add.sprite(400, 300, 'contra2');
|
||||
contra.physicsEnabled = true;
|
||||
contra.body.clearShapes();
|
||||
contra.body.loadPolygon('physicsData', 'contra2');
|
||||
|
||||
game.input.onDown.add(function() { start = true; }, this);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (start)
|
||||
{
|
||||
contra.body.rotateLeft(5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderPhysicsBody(contra.body, '#00ffff');
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user