| 157 | * @param {} [options] |
| 158 | */ |
| 159 | var _initProperties = function(body, options) { |
| 160 | options = options || {}; |
| 161 | |
| 162 | // init required properties (order is important) |
| 163 | Body.set(body, { |
| 164 | bounds: body.bounds || Bounds.create(body.vertices), |
| 165 | positionPrev: body.positionPrev || Vector.clone(body.position), |
| 166 | anglePrev: body.anglePrev || body.angle, |
| 167 | vertices: body.vertices, |
| 168 | parts: body.parts || [body], |
| 169 | isStatic: body.isStatic, |
| 170 | isSleeping: body.isSleeping, |
| 171 | parent: body.parent || body |
| 172 | }); |
| 173 | |
| 174 | Vertices.rotate(body.vertices, body.angle, body.position); |
| 175 | Axes.rotate(body.axes, body.angle); |
| 176 | Bounds.update(body.bounds, body.vertices, body.velocity); |
| 177 | |
| 178 | // allow options to override the automatically calculated properties |
| 179 | Body.set(body, { |
| 180 | axes: options.axes || body.axes, |
| 181 | area: options.area || body.area, |
| 182 | mass: options.mass || body.mass, |
| 183 | inertia: options.inertia || body.inertia |
| 184 | }); |
| 185 | |
| 186 | // render properties |
| 187 | var defaultFillStyle = (body.isStatic ? '#2e2b44' : Common.choose(['#006BA6', '#0496FF', '#FFBC42', '#D81159', '#8F2D56'])), |
| 188 | defaultStrokeStyle = '#000'; |
| 189 | body.render.fillStyle = body.render.fillStyle || defaultFillStyle; |
| 190 | body.render.strokeStyle = body.render.strokeStyle || defaultStrokeStyle; |
| 191 | body.render.sprite.xOffset += -(body.bounds.min.x - body.position.x) / (body.bounds.max.x - body.bounds.min.x); |
| 192 | body.render.sprite.yOffset += -(body.bounds.min.y - body.position.y) / (body.bounds.max.y - body.bounds.min.y); |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * Given a property and a value (or map of), sets the property(s) on the body, using the appropriate setter functions if they exist. |