新增tire。修改transform.Component为es.ComponentTransform

This commit is contained in:
yhh
2021-07-04 21:03:30 +08:00
parent dc3d639824
commit 77ad112f67
11 changed files with 6591 additions and 40 deletions

View File

@@ -80,7 +80,7 @@ module es {
* 当实体的位置改变时调用。这允许组件知道它们由于父实体的移动而移动了。
* @param comp
*/
public onEntityTransformChanged(comp: transform.Component) {
public onEntityTransformChanged(comp: ComponentTransform) {
}
public debugRender(batcher: IBatcher) {}

View File

@@ -152,15 +152,15 @@ module es {
this._isParentEntityAddedToScene = false;
}
public onEntityTransformChanged(comp: transform.Component) {
public onEntityTransformChanged(comp: ComponentTransform) {
switch (comp) {
case transform.Component.position:
case ComponentTransform.position:
this._isPositionDirty = true;
break;
case transform.Component.scale:
case ComponentTransform.scale:
this._isPositionDirty = true;
break;
case transform.Component.rotation:
case ComponentTransform.rotation:
this._isRotationDirty = true;
break;
}

View File

@@ -32,7 +32,7 @@ module es {
protected _renderLayer: number = 0;
public onEntityTransformChanged(comp: transform.Component) {
public onEntityTransformChanged(comp: ComponentTransform) {
this._areBoundsDirty = true;
}

View File

@@ -192,7 +192,7 @@ module es {
return this.transform.worldToLocalTransform;
}
public onTransformChanged(comp: transform.Component) {
public onTransformChanged(comp: ComponentTransform) {
// 通知我们的子项改变了位置
this.components.onEntityTransformChanged(comp);
}

View File

@@ -1,12 +1,10 @@
module transform {
export enum Component {
module es {
export enum ComponentTransform {
position,
scale,
rotation,
}
}
module es {
export enum DirtyType {
clean = 0,
positionDirty = 1,
@@ -458,13 +456,13 @@ module es {
switch (dirtyFlagType) {
case DirtyType.positionDirty:
this.entity.onTransformChanged(transform.Component.position);
this.entity.onTransformChanged(ComponentTransform.position);
break;
case DirtyType.rotationDirty:
this.entity.onTransformChanged(transform.Component.rotation);
this.entity.onTransformChanged(ComponentTransform.rotation);
break;
case DirtyType.scaleDirty:
this.entity.onTransformChanged(transform.Component.scale);
this.entity.onTransformChanged(ComponentTransform.scale);
break;
}

View File

@@ -294,7 +294,7 @@ module es {
}
}
public onEntityTransformChanged(comp: transform.Component) {
public onEntityTransformChanged(comp: ComponentTransform) {
if (this._components.length > 0 ){
for (let i = 0, s = this._components.length; i < s; ++ i) {
let component = this._components[i];

View File

@@ -0,0 +1,23 @@
module es {
export class Tire extends Composite {
constructor(origin: Vector2, radius: number, segments: number, spokeStiffness: number = 1, treadStiffness: number = 1) {
super();
const stride = 2 * Math.PI / segments;
for (let i = 0; i < segments; i ++) {
const theta = i * stride;
this.addParticle(new Particle(new Vector2(origin.x + Math.cos(theta) * radius,
origin.y + Math.sin(theta) * radius)));
}
const centerParticle = this.addParticle(new Particle(origin));
for (let i = 0; i < segments; i ++) {
this.addConstraint(new DistanceConstraint(this.particles[i], this.particles[(i + 1) % segments], treadStiffness));
this.addConstraint(new DistanceConstraint(this.particles[i], centerParticle, spokeStiffness))
.setCollidesWithColliders(false);
this.addConstraint(new DistanceConstraint(this.particles[i], this.particles[(i + 5) % segments], treadStiffness));
}
}
}
}