新增虚拟输入类 VirtualInput
This commit is contained in:
@@ -127,15 +127,5 @@ module es {
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建此组件的克隆
|
||||
*/
|
||||
public clone(): Component {
|
||||
let component = ObjectUtils.clone<Component>(this);
|
||||
component.entity = null;
|
||||
|
||||
return component;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,24 @@ module es {
|
||||
/**
|
||||
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
||||
*/
|
||||
constructor() {
|
||||
constructor(x?: number, y?: number, width?: number, height?: number) {
|
||||
super();
|
||||
|
||||
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
|
||||
this.shape = new Box(1, 1);
|
||||
this._colliderRequiresAutoSizing = true;
|
||||
if (x == undefined && y == undefined){
|
||||
if (width == undefined && height == undefined){
|
||||
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
|
||||
this.shape = new Box(1, 1);
|
||||
this._colliderRequiresAutoSizing = true;
|
||||
}else if (width != undefined && height != undefined){
|
||||
x = -width / 2;
|
||||
y = -height / 2;
|
||||
this._localOffset = new Vector2(x + width / 2, y + height / 2);
|
||||
this.shape = new Box(width, height);
|
||||
}
|
||||
}else if (x != undefined && y != undefined && width != undefined && height != undefined){
|
||||
this._localOffset = new Vector2(x + width / 2, y + height / 2);
|
||||
this.shape = new Box(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public get width() {
|
||||
@@ -32,20 +44,6 @@ module es {
|
||||
this.setHeight(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个BoxCollider并使用x/y组件作为localOffset
|
||||
* @param x
|
||||
* @param y
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public createBoxRect(x: number, y: number, width: number, height: number): BoxCollider{
|
||||
this._localOffset = new Vector2(x + width / 2, y + width / 2);
|
||||
this.shape = new Box(width, height);
|
||||
this._colliderRequiresAutoSizing = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置BoxCollider的大小
|
||||
* @param width
|
||||
@@ -110,11 +108,11 @@ module es {
|
||||
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();
|
||||
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();
|
||||
|
||||
this.polygonShape.graphics.clear();
|
||||
if (poly.points.length >= 2){
|
||||
|
||||
@@ -13,11 +13,14 @@ module es {
|
||||
constructor(radius?: number) {
|
||||
super();
|
||||
|
||||
if (radius)
|
||||
if (radius == undefined){
|
||||
// 我们在这里插入一个1px的圆圈作为占位符
|
||||
// 直到碰撞器被添加到实体并可以获得更精确的自动调整大小数据的下一帧
|
||||
this.shape = new Circle(1);
|
||||
this._colliderRequiresAutoSizing = true;
|
||||
// 我们在这里插入一个1px的圆圈作为占位符
|
||||
// 直到碰撞器被添加到实体并可以获得更精确的自动调整大小数据的下一帧
|
||||
this.shape = new Circle(radius ? radius : 1);
|
||||
}else{
|
||||
this.shape = new Circle(radius);
|
||||
}
|
||||
}
|
||||
|
||||
public get radius(): number {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module es {
|
||||
export abstract class Collider extends Component {
|
||||
public debug
|
||||
/**
|
||||
* 对撞机的基本形状
|
||||
*/
|
||||
@@ -12,12 +11,12 @@ module es {
|
||||
/**
|
||||
* 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法
|
||||
*/
|
||||
public physicsLayer = 1 << 0;
|
||||
public physicsLayer = new Ref(1 << 0);
|
||||
/**
|
||||
* 碰撞器在使用移动器移动时应该碰撞的层
|
||||
* 默认为所有层
|
||||
*/
|
||||
public collidesWithLayers = Physics.allLayers;
|
||||
public collidesWithLayers: Ref<number> = new Ref(Physics.allLayers);
|
||||
/**
|
||||
* 如果为true,碰撞器将根据附加的变换缩放和旋转
|
||||
*/
|
||||
@@ -124,8 +123,8 @@ module es {
|
||||
let renderableBounds = renderable.bounds;
|
||||
|
||||
// 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染
|
||||
let width = renderableBounds.width / this.entity.scale.x;
|
||||
let height = renderableBounds.height / this.entity.scale.y;
|
||||
let width = renderableBounds.width / this.entity.transform.scale.x;
|
||||
let height = renderableBounds.height / this.entity.transform.scale.y;
|
||||
// 圆碰撞器需要特别注意原点
|
||||
if (this instanceof CircleCollider) {
|
||||
this.radius = Math.max(width, height) * 0.5;
|
||||
@@ -214,7 +213,7 @@ module es {
|
||||
public collidesWith(collider: Collider, motion: Vector2, result: CollisionResult): boolean {
|
||||
// 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠
|
||||
let oldPosition = this.entity.position;
|
||||
this.entity.position = this.entity.position.add(motion);
|
||||
this.entity.position.add(motion);
|
||||
|
||||
let didCollide = this.shape.collidesWithShape(collider.shape, result);
|
||||
if (didCollide)
|
||||
@@ -225,15 +224,5 @@ module es {
|
||||
|
||||
return didCollide;
|
||||
}
|
||||
|
||||
public clone(): Component {
|
||||
let collider = ObjectUtils.clone<Collider>(this);
|
||||
collider.entity = null;
|
||||
|
||||
if (this.shape)
|
||||
collider.shape = this.shape.clone();
|
||||
|
||||
return collider;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ module es {
|
||||
let bounds = collider.bounds;
|
||||
bounds.x += motion.x;
|
||||
bounds.y += motion.y;
|
||||
let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers);
|
||||
let neighbors = Physics.boxcastBroadphaseExcludingSelf(collider, bounds, collider.collidesWithLayers.value);
|
||||
|
||||
for (let j = 0; j < neighbors.length; j++) {
|
||||
let neighbor = neighbors[j];
|
||||
|
||||
@@ -24,13 +24,12 @@ module es {
|
||||
let didCollide = false;
|
||||
|
||||
// 获取我们在新位置可能发生碰撞的任何东西
|
||||
this.entity.position = Vector2.add(this.entity.position, motion);
|
||||
this.entity.position.add(motion);
|
||||
|
||||
// 获取任何可能在新位置发生碰撞的东西
|
||||
let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers);
|
||||
for (let i = 0; i < neighbors.length; i++) {
|
||||
let neighbor = neighbors[i];
|
||||
if (this._collider.overlaps(neighbor) && neighbor.enabled) {
|
||||
let neighbors = Physics.boxcastBroadphase(this._collider.bounds, this._collider.collidesWithLayers.value);
|
||||
for (let neighbor of neighbors){
|
||||
if (this._collider.overlaps(neighbor) && neighbor.enabled){
|
||||
didCollide = true;
|
||||
this.notifyTriggerListeners(this._collider, neighbor);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ module es {
|
||||
public readonly sprites: Sprite[];
|
||||
public readonly frameRate: number;
|
||||
|
||||
constructor(sprites: Sprite[], frameRate: number) {
|
||||
constructor(sprites: Sprite[], frameRate: number = 10) {
|
||||
this.sprites = sprites;
|
||||
this.frameRate = frameRate;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module es {
|
||||
export class TiledMapRenderer extends RenderableComponent {
|
||||
public tiledMap: TmxMap;
|
||||
public physicsLayer: number = 1 << 0;
|
||||
public physicsLayer: Ref<number> = new Ref(1 << 0);
|
||||
/**
|
||||
* 如果空,所有层将被渲染
|
||||
*/
|
||||
@@ -27,7 +27,7 @@ module es {
|
||||
this.displayObject = new egret.DisplayObjectContainer();
|
||||
|
||||
if (collisionLayerName) {
|
||||
this.collisionLayer = tiledMap.tileLayers[collisionLayerName];
|
||||
this.collisionLayer = tiledMap.tileLayers.find(layer => layer.name == collisionLayerName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ module es {
|
||||
// 为我们收到的矩形创建碰撞器
|
||||
this._colliders = [];
|
||||
for (let i = 0; i < collisionRects.length; i++) {
|
||||
let collider = new BoxCollider().createBoxRect(collisionRects[i].x + this._localOffset.x,
|
||||
let collider = new BoxCollider(collisionRects[i].x + this._localOffset.x,
|
||||
collisionRects[i].y + this._localOffset.y, collisionRects[i].width, collisionRects[i].height);
|
||||
collider.physicsLayer = this.physicsLayer;
|
||||
collider.entity = this.entity;
|
||||
|
||||
@@ -200,6 +200,7 @@ module es {
|
||||
|
||||
// 更新我们所有的系统管理器
|
||||
Time.update(egret.getTimer());
|
||||
Input.update();
|
||||
|
||||
if (this._scene) {
|
||||
for (let i = this._globalManagers.length - 1; i >= 0; i--) {
|
||||
|
||||
@@ -280,20 +280,6 @@ module es {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建此实体的深层克隆。子类可以重写此方法来复制任何自定义字段。
|
||||
* 当重写时,应该调用CopyFrom方法,它将为您克隆所有组件、碰撞器和转换子组件。
|
||||
* 注意克隆的实体不会被添加到任何场景中!你必须自己添加它们!
|
||||
* @param position
|
||||
*/
|
||||
public clone(position: Vector2 = new Vector2()): Entity {
|
||||
let entity = new Entity(this.name + "(clone)");
|
||||
entity.copyFrom(this);
|
||||
entity.transform.position = position;
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在提交了所有挂起的实体更改后,将此实体添加到场景时调用
|
||||
*/
|
||||
@@ -413,31 +399,5 @@ module es {
|
||||
public toString(): string {
|
||||
return `[Entity: name: ${this.name}, tag: ${this.tag}, enabled: ${this.enabled}, depth: ${this.updateOrder}]`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将实体的属性、组件和碰撞器复制到此实例
|
||||
* @param entity
|
||||
*/
|
||||
protected copyFrom(entity: Entity) {
|
||||
this.tag = entity.tag;
|
||||
this.updateInterval = entity.updateInterval;
|
||||
this.updateOrder = entity.updateOrder;
|
||||
this.enabled = entity.enabled;
|
||||
|
||||
this.transform.scale = entity.transform.scale;
|
||||
this.transform.rotation = entity.transform.rotation;
|
||||
|
||||
for (let i = 0; i < entity.components.count; i++)
|
||||
this.addComponent(entity.components.buffer[i].clone());
|
||||
for (let i = 0; i < entity.components._componentsToAdd.length; i++)
|
||||
this.addComponent(entity.components._componentsToAdd[i].clone());
|
||||
|
||||
for (let i = 0; i < entity.transform.childCount; i++) {
|
||||
let child = entity.transform.getChild(i).entity;
|
||||
let childClone = child.clone();
|
||||
childClone.transform.copyFrom(child.transform);
|
||||
childClone.transform.parent = this.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user