Skip to content

Commit 2c10075

Browse files
committed
Body.setPolygon converted and working, along with some other p2 Body methods hoisted up.
1 parent ab5c07d commit 2c10075

3 files changed

Lines changed: 273 additions & 117 deletions

File tree

examples/wip/p26.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
game.load.image('box', 'assets/sprites/block.png');
7+
8+
}
9+
10+
var box;
11+
var move = false;
12+
var start = 0;
13+
var end = 0;
14+
15+
function create() {
16+
17+
box = game.add.sprite(200, 200, 'box');
18+
box.physicsEnabled = true;
19+
20+
// Works
21+
// box.body.setPolygon({}, [ [-1, 1], [-1, 0], [1, 0], [1, 1], [0.5, 0.5] ]);
22+
23+
// Works
24+
// box.body.setPolygon({}, [-1, 1], [-1, 0], [1, 0], [1, 1], [0.5, 0.5]);
25+
26+
// Works
27+
// box.body.setPolygon({}, -100, 100, -100, 0, 100, 0, 100, 100, 50, 50);
28+
29+
box.body.setPolygon({}, -1, 1, -1, 0, 1, 0, 1, 1, 0.5, 0.5);
30+
31+
32+
var path = [[-1, 1],
33+
[-1, 0],
34+
[1, 0],
35+
[1, 1],
36+
[0.5, 0.5]];
37+
38+
// box.body.data.fromPolygon(path);
39+
40+
console.log('real path');
41+
console.log(path);
42+
43+
44+
45+
// box.body.setZeroDamping();
46+
47+
// game.input.onDown.addOnce(startTiming, this);
48+
49+
}
50+
51+
function startTiming() {
52+
53+
start = game.time.now;
54+
end = start + 1000;
55+
move = true;
56+
57+
}
58+
59+
function update() {
60+
61+
if (move)
62+
{
63+
box.body.moveLeft(100);
64+
65+
if (game.time.now >= end)
66+
{
67+
move = false;
68+
var duration = game.time.now - start;
69+
console.log('Test over. Distance: ', box.x, 'duration', duration);
70+
}
71+
}
72+
else
73+
{
74+
box.body.setZeroVelocity();
75+
}
76+
77+
}
78+
79+
function render() {
80+
81+
game.debug.renderText('x: ' + box.body.velocity.x, 32, 32);
82+
game.debug.renderText('y: ' + box.body.velocity.y, 32, 64);
83+
84+
}

src/gameobjects/Sprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
270270

271271
if (this.body)
272272
{
273-
this.body.preUpdate();
273+
// this.body.preUpdate();
274274
}
275275

276276
return true;

0 commit comments

Comments
 (0)