为boxCollider与spriteRenderer新增debugRender
This commit is contained in:
@@ -362,7 +362,7 @@ module es {
|
||||
}
|
||||
|
||||
public update() {
|
||||
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5));
|
||||
let halfScreen = Vector2.multiply(this.bounds.size, new Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
@@ -385,7 +385,7 @@ module es {
|
||||
* @param position
|
||||
*/
|
||||
public clampToMapSize(position: Vector2) {
|
||||
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5)).add(new Vector2(this.mapSize.x, this.mapSize.y));
|
||||
let halfScreen = Vector2.multiply(this.bounds.size, new Vector2(0.5)).add(new Vector2(this.mapSize.x, this.mapSize.y));
|
||||
let cameraMax = new Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
|
||||
return Vector2.clamp(position, halfScreen, cameraMax);
|
||||
|
||||
@@ -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}]`;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module es {
|
||||
export abstract class Collider extends Component {
|
||||
public debug
|
||||
/**
|
||||
* 对撞机的基本形状
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,8 @@ module es {
|
||||
* 用于装载egret显示对象
|
||||
*/
|
||||
public displayObject: egret.DisplayObject = new egret.DisplayObject();
|
||||
public hollowShape: egret.Shape = new egret.Shape();
|
||||
public pixelShape: egret.Shape = new egret.Shape();
|
||||
/**
|
||||
* 用于着色器处理精灵
|
||||
*/
|
||||
@@ -30,6 +32,7 @@ module es {
|
||||
return this.bounds.height;
|
||||
}
|
||||
|
||||
public debugRenderEnabled: boolean = true;
|
||||
protected _localOffset: Vector2 = Vector2.zero;
|
||||
|
||||
/**
|
||||
@@ -109,6 +112,32 @@ module es {
|
||||
*/
|
||||
public abstract render(camera: Camera);
|
||||
|
||||
public debugRender() {
|
||||
if (!this.debugRenderEnabled)
|
||||
return;
|
||||
|
||||
if (!this.hollowShape.parent)
|
||||
this.debugDisplayObject.addChild(this.hollowShape);
|
||||
|
||||
if (!this.pixelShape.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape);
|
||||
|
||||
if (!this.entity.getComponent(Collider)){
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(Colors.renderableBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(1, Colors.renderableBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
}
|
||||
|
||||
let pixelPos = Vector2.add(this.entity.transform.position, this._localOffset);
|
||||
this.pixelShape.graphics.clear();
|
||||
this.pixelShape.graphics.beginFill(Colors.renderableCenter, 0);
|
||||
this.pixelShape.graphics.lineStyle(4, Colors.renderableCenter);
|
||||
this.pixelShape.graphics.lineTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.endFill();
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果renderableComponent的边界与camera.bounds相交 返回true
|
||||
* 用于处理isVisible标志的状态开关
|
||||
@@ -184,6 +213,7 @@ module es {
|
||||
*/
|
||||
protected onBecameVisible() {
|
||||
this.displayObject.visible = this.isVisible;
|
||||
this.debugDisplayObject.visible = this.isVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,6 +222,7 @@ module es {
|
||||
*/
|
||||
protected onBecameInvisible() {
|
||||
this.displayObject.visible = this.isVisible;
|
||||
this.debugDisplayObject.visible = this.isVisible;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user