移除 transform
This commit is contained in:
@@ -1,57 +1,32 @@
|
||||
class Mesh extends Component {
|
||||
private _verts: VertexPosition[];
|
||||
private _primitiveCount: number;
|
||||
private _triangles: number[];
|
||||
private _topLeftVertPosition: Vector2;
|
||||
private _width;
|
||||
private _height;
|
||||
///<reference path="./RenderableComponent.ts" />
|
||||
class Mesh extends RenderableComponent {
|
||||
private _mesh: egret.Mesh;
|
||||
|
||||
public initialize() {
|
||||
constructor(){
|
||||
super();
|
||||
|
||||
this._mesh = new egret.Mesh();
|
||||
}
|
||||
|
||||
public setVertPosition(positions: Vector2[]){
|
||||
let createVerts = !this._verts || this._verts.length != positions.length;
|
||||
if (createVerts)
|
||||
this._verts = new Array(positions.length);
|
||||
|
||||
for (let i = 0; i < this._verts.length; i ++){
|
||||
this._verts[i] = new VertexPosition(positions[i]);
|
||||
}
|
||||
public setTexture(texture: egret.Texture): Mesh{
|
||||
this._mesh.texture = texture;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setTriangles(triangles: number[]){
|
||||
this._primitiveCount = triangles.length / 3;
|
||||
this._triangles = triangles;
|
||||
return this;
|
||||
public onAddedToEntity(){
|
||||
this.addChild(this._mesh);
|
||||
}
|
||||
|
||||
public recalculateBounds(){
|
||||
this._topLeftVertPosition = new Vector2(Number.MAX_VALUE, Number.MAX_VALUE);
|
||||
let max = new Vector2(Number.MIN_VALUE, Number.MIN_VALUE);
|
||||
|
||||
for (let i = 0; i < this._verts.length; i ++){
|
||||
this._topLeftVertPosition.x = Math.min(this._topLeftVertPosition.x, this._verts[i].position.x);
|
||||
this._topLeftVertPosition.y = Math.min(this._topLeftVertPosition.y, this._verts[i].position.y);
|
||||
max.x = Math.max(max.x, this._verts[i].position.x);
|
||||
max.y = Math.max(max.y, this._verts[i].position.y);
|
||||
}
|
||||
|
||||
this._width = max.x - this._topLeftVertPosition.x;
|
||||
this._height = max.y - this._topLeftVertPosition.y;
|
||||
|
||||
return this;
|
||||
public onRemovedFromEntity(){
|
||||
this.removeChild(this._mesh);
|
||||
}
|
||||
|
||||
public render(){
|
||||
public render(camera: Camera){
|
||||
this.x = this.entity.position.x - camera.position.x + camera.origin.x;
|
||||
this.y = this.entity.position.y - camera.position.y + camera.origin.y;
|
||||
}
|
||||
}
|
||||
|
||||
class VertexPosition{
|
||||
public position: Vector2;
|
||||
|
||||
constructor(position: Vector2){
|
||||
this.position = position;
|
||||
public reset() {
|
||||
}
|
||||
}
|
||||
@@ -104,23 +104,6 @@ abstract class Collider extends Component{
|
||||
this._isParentEntityAddedToScene = false;
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
switch (comp){
|
||||
case ComponentTransform.position:
|
||||
this._isPositionDirty = true;
|
||||
break;
|
||||
case ComponentTransform.scale:
|
||||
this._isPositionDirty = true;
|
||||
break;
|
||||
case ComponentTransform.rotation:
|
||||
this._isRotationDirty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this._isColliderRegistered)
|
||||
Physics.updateCollider(this);
|
||||
}
|
||||
|
||||
public onEnabled(){
|
||||
this.registerColliderWithPhysicsSystem();
|
||||
this._isPositionDirty = this._isRotationDirty = true;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
class PolygonMesh extends Mesh {
|
||||
constructor(points: Vector2[], arePointsCCW: boolean = true){
|
||||
super();
|
||||
|
||||
let triangulator = new Triangulator();
|
||||
triangulator.triangulate(points, arePointsCCW);
|
||||
|
||||
this.setVertPosition(points);
|
||||
this.setTriangles(triangulator.triangleIndices);
|
||||
this.recalculateBounds();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
///<reference path="./PooledComponent.ts" />
|
||||
/**
|
||||
* 所有可渲染组件的基类
|
||||
*/
|
||||
@@ -52,8 +53,4 @@ abstract class RenderableComponent extends PooledComponent implements IRenderabl
|
||||
this.isVisible = camera.getBounds().intersects(this.getBounds());
|
||||
return this.isVisible;
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
this._areBoundsDirty = true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
class ScreenSpaceCamera extends Camera {
|
||||
protected updateMatrixes(){
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user