-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcircle.class.js
46 lines (32 loc) · 1.25 KB
/
circle.class.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function (global) {
var b2BodyDef = Box2D.Dynamics.b2BodyDef
, b2Body = Box2D.Dynamics.b2Body
, b2FixtureDef = Box2D.Dynamics.b2FixtureDef
, b2CircleShape = Box2D.Collision.Shapes.b2CircleShape
;
function Circle (game, x, y, phaserImage, scale, world, radius, density, damping) {
var bodyDef = new b2BodyDef;
var fixDef = new b2FixtureDef;
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.x = x / 30;
bodyDef.position.y = y / 30;
this.body = world.CreateBody(bodyDef);
fixDef.shape = new b2CircleShape(
radius //radius
);
fixDef.restitution = 0.5;
fixDef.density = density;
this.body.CreateFixture(fixDef);
this.body.SetLinearDamping(damping);
this.body.SetAngularDamping(damping);
this.image = game.add.sprite(x, y, phaserImage);
this.image.anchor.setTo(0.5, 0.5);
this.image.scale.set(scale, scale);
}
Circle.prototype.update = function () {
var bodyCenter = this.body.GetWorldCenter();
this.image.x = bodyCenter.x * 30;
this.image.y = bodyCenter.y * 30;
}
global.Circle = Circle;
})(window);