Commit 52ef2046 authored by wildfirecode's avatar wildfirecode

1

parent 5eca0d6b
import { addImage } from "./utils";
import { FACTOR } from "./consts";
export default class Ball extends p2.Body {
_skin: egret.DisplayObject;
constructor(options?: any) {
super(options);
this.init();
}
private init() {
init() {
this._skin = addImage('ball_png');
this._skin.anchorOffsetX = this._skin.width / 2;
this._skin.anchorOffsetY = this._skin.height / 2;
const radius = this._skin.width / 2;
const radius = this._skin.width / 2 / FACTOR;
const shape = new p2.Circle({ radius: radius });
this.addShape(shape);
......@@ -20,8 +17,8 @@ export default class Ball extends p2.Body {
}
updateSkin() {
this._skin.x = this.position[0];
this._skin.y = this.position[1];
this._skin.x = this.position[0] * FACTOR;
this._skin.y = this.position[1] * FACTOR;
this._skin.rotation = this.angle * 180 / Math.PI;
}
......
......@@ -23,6 +23,7 @@ export default class Gun extends egret.Sprite {
addBall() {
const ball = new Ball();
ball.init();
this._world.addBody(ball);
this._root.addChild(ball.skin);
}
......
......@@ -29,7 +29,7 @@ export class Main extends eui.UILayer {
}
loop() {
this._world.step(1 / 60);
this._world.step(1);
this._world.loop();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment