2014-02-12 05:34:31 +00:00
|
|
|
|
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
2014-02-14 22:30:24 +00:00
|
|
|
game.load.image('box', 'assets/sprites/diamond.png');
|
2014-02-14 23:51:49 +00:00
|
|
|
game.load.physics('physobjects', 'assets/physics/diamond.json');
|
2014-02-12 05:34:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var box;
|
|
|
|
var bmd;
|
|
|
|
var move = false;
|
|
|
|
var start = 0;
|
|
|
|
var end = 0;
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
bmd = game.add.bitmapData(800, 600);
|
|
|
|
game.add.image(0, 0, bmd);
|
|
|
|
|
|
|
|
box = game.add.sprite(300, 300, 'box');
|
|
|
|
// box.anchor.set(0.5);
|
|
|
|
|
|
|
|
box.physicsEnabled = true;
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
box.body.clearShapes();
|
|
|
|
|
|
|
|
box.body.loadPolygon('physobjects', 'diamond');
|
|
|
|
|
2014-02-14 21:49:02 +00:00
|
|
|
box.body.rotateLeft(20);
|
2014-02-12 05:34:31 +00:00
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
// console.log(game.cache.getPhysicsData('physobjects', 'diamond'));
|
|
|
|
|
2014-02-12 05:34:31 +00:00
|
|
|
// 95x95
|
|
|
|
// box.body.setRectangle(64, 64);
|
|
|
|
|
|
|
|
// box.body.setRectangle(64, 64, 95/2,95/2);
|
|
|
|
|
|
|
|
// Works
|
2014-02-14 22:30:24 +00:00
|
|
|
// box.body.clearShapes();
|
2014-02-14 21:49:02 +00:00
|
|
|
// box.body.addPolygon({}, [ [-1, 1], [-1, 0], [1, 0], [1, 1], [0.5, 0.5] ]);
|
2014-02-12 05:34:31 +00:00
|
|
|
|
|
|
|
// Works
|
|
|
|
// box.body.setPolygon({}, [-1, 1], [-1, 0], [1, 0], [1, 1], [0.5, 0.5]);
|
|
|
|
|
|
|
|
// Works
|
2014-02-14 22:30:24 +00:00
|
|
|
// box.body.addPolygon({}, -100, 100, -100, 0, 100, 0, 100, 100, 50, 50);
|
|
|
|
|
2014-02-14 23:51:49 +00:00
|
|
|
// box.body.addPolygon({}, -100, 100, -100, 0, 100, 0, 100, 100, 50, 50 );
|
|
|
|
|
|
|
|
// box.body.addPolygon({}, 32, 13 , 17, 28 , 15, 28 , 0, 13 , 0, 7 , 7, 0 , 25, 0 , 32, 7 );
|
2014-02-12 05:34:31 +00:00
|
|
|
|
|
|
|
// Works
|
|
|
|
// box.body.setPolygon({}, -1, 1, -1, 0, 1, 0, 1, 1, 0.5, 0.5);
|
|
|
|
|
2014-02-14 21:49:02 +00:00
|
|
|
// box.body.setZeroDamping();
|
2014-02-12 05:34:31 +00:00
|
|
|
|
2014-02-14 21:49:02 +00:00
|
|
|
// game.input.onDown.addOnce(startTiming, this);
|
2014-02-12 05:34:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function startTiming() {
|
|
|
|
|
|
|
|
start = game.time.now;
|
|
|
|
end = start + 1000;
|
|
|
|
move = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
|
|
|
if (move)
|
|
|
|
{
|
|
|
|
box.body.moveLeft(100);
|
|
|
|
|
|
|
|
// if (game.time.now >= end)
|
|
|
|
// {
|
|
|
|
// move = false;
|
|
|
|
// var duration = game.time.now - start;
|
|
|
|
// console.log('Test over. Distance: ', box.x, 'duration', duration);
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-14 21:49:02 +00:00
|
|
|
// box.body.setZeroVelocity();
|
2014-02-12 05:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
2014-02-14 22:30:24 +00:00
|
|
|
game.debug.renderPhysicsBody(box.body, 0);
|
2014-02-12 05:34:31 +00:00
|
|
|
|
2014-02-14 21:49:02 +00:00
|
|
|
// game.debug.renderText(box.body., 32, 32);
|
2014-02-12 05:34:31 +00:00
|
|
|
// game.debug.renderText('y: ' + box.body.velocity.y, 32, 64);
|
|
|
|
|
|
|
|
}
|