为boxCollider与spriteRenderer新增debugRender

This commit is contained in:
YHH
2020-08-24 09:06:25 +08:00
parent 7345a17d24
commit 27f9e78fe5
19 changed files with 699 additions and 421 deletions

View File

@@ -1,6 +1,10 @@
///<reference path="./Collider.ts" />
module es {
export class BoxCollider extends Collider {
public hollowShape: egret.Shape = new egret.Shape();
public polygonShape: egret.Shape = new egret.Shape();
public pixelShape1: egret.Shape = new egret.Shape();
public pixelShape2: egret.Shape = new egret.Shape();
/**
* 零参数构造函数要求RenderableComponent在实体上这样碰撞器可以在实体被添加到场景时调整自身的大小。
*/
@@ -92,6 +96,27 @@ module es {
}
}
public debugRender() {
let poly = this.shape;
if (!this.hollowShape.parent)
this.debugDisplayObject.addChild(this.hollowShape);
if (!this.polygonShape.parent)
this.debugDisplayObject.addChild(this.polygonShape);
if (!this.pixelShape1.parent)
this.debugDisplayObject.addChild(this.pixelShape1);
if (!this.pixelShape2.parent)
this.debugDisplayObject.addChild(this.pixelShape2);
this.hollowShape.graphics.clear();
this.hollowShape.graphics.beginFill(Colors.colliderBounds, 0);
this.hollowShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderBounds);
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
this.hollowShape.graphics.endFill();
}
public toString() {
return `[BoxCollider: bounds: ${this.bounds}]`;
}

View File

@@ -1,5 +1,6 @@
module es {
export abstract class Collider extends Component {
public debug
/**
* 对撞机的基本形状
*/