fix: quack quack
This commit is contained in:
parent
b5a71ccdc6
commit
9d0897608e
|
@ -6,9 +6,6 @@ import {
|
|||
} from 'matter-js';
|
||||
|
||||
import AbstractBody from '../abstract/body';
|
||||
import ShapeList from '../shape/list';
|
||||
import CircleShape from '../shape/circle';
|
||||
import RectangleShape from '../shape/rectangle';
|
||||
|
||||
// Translate "real" coordinates to physics coordinates.
|
||||
export const SCALE = 1 / 12;
|
||||
|
@ -55,7 +52,7 @@ export default class Body extends AbstractBody {
|
|||
|
||||
static bodyFromShape(shape) {
|
||||
const shapePosition = Vector.scale(shape.position, 1 / SCALE);
|
||||
if (shape instanceof ShapeList) {
|
||||
if (shape.children) {
|
||||
const children = [];
|
||||
for (let i = 0; i < shape.children.length; i++) {
|
||||
const child = shape.children[i];
|
||||
|
@ -71,12 +68,12 @@ export default class Body extends AbstractBody {
|
|||
const {x, y} = body.position;
|
||||
return [body, shapePosition, [x, y]];
|
||||
}
|
||||
if (shape instanceof RectangleShape) {
|
||||
if (shape.width) {
|
||||
const [width, height] = Vector.scale(shape.size, 1 / SCALE);
|
||||
const body = Bodies.rectangle(0, 0, width, height);
|
||||
return [body, shapePosition, [0, 0]];
|
||||
}
|
||||
if (shape instanceof CircleShape) {
|
||||
if (shape.radius) {
|
||||
const body = Bodies.circle(0, 0, shape.radius / SCALE);
|
||||
return [body, shapePosition, [0, 0]];
|
||||
}
|
||||
|
|
|
@ -5,25 +5,21 @@ import {
|
|||
Renderable,
|
||||
} from '@avocado/graphics';
|
||||
|
||||
import ShapeList from './list';
|
||||
import CircleShape from './circle';
|
||||
import PolygonShape from './polygon';
|
||||
|
||||
export default class ShapeView extends Renderable {
|
||||
|
||||
constructor(shape) {
|
||||
super();
|
||||
this.container = new Container();
|
||||
this.shape = shape;
|
||||
if (shape instanceof PolygonShape) {
|
||||
if (shape.vertices) {
|
||||
this.redrawPolygonLines();
|
||||
shape.on('aabbChanged', this.onPolygonShapeAabbChanged, this);
|
||||
}
|
||||
if (shape instanceof CircleShape) {
|
||||
if (shape.radius) {
|
||||
this.redrawCircle();
|
||||
shape.on('aabbChanged', this.onCircleShapeAabbChanged, this);
|
||||
}
|
||||
if (shape instanceof ShapeList) {
|
||||
if (shape.children) {
|
||||
for (let i = 0; i < shape.children.length; i++) {
|
||||
const child = shape.children[i];
|
||||
const childShapeView = new ShapeView(child);
|
||||
|
@ -36,10 +32,10 @@ export default class ShapeView extends Renderable {
|
|||
|
||||
destroy() {
|
||||
super.destroy();
|
||||
if (this.shape instanceof PolygonShape) {
|
||||
if (this.shape.vertices) {
|
||||
this.shape.off('aabbChanged', this.onPolygonShapeAabbChanged);
|
||||
}
|
||||
if (this.shape instanceof CircleShape) {
|
||||
if (this.shape.radius) {
|
||||
this.shape.off('aabbChanged', this.onCircleShapeAabbChanged);
|
||||
}
|
||||
this.shape.off('aabbChanged', this.onShapePositionChanged);
|
||||
|
|
Loading…
Reference in New Issue
Block a user