内置tween管理器
This commit is contained in:
@@ -3,11 +3,11 @@ module es {
|
||||
public getwidth() {
|
||||
return this.bounds.width;
|
||||
}
|
||||
|
||||
|
||||
public getheight() {
|
||||
return this.bounds.height;
|
||||
}
|
||||
|
||||
|
||||
protected _bounds: es.Rectangle = new es.Rectangle();
|
||||
public getbounds(): es.Rectangle {
|
||||
if (this._areBoundsDirty) {
|
||||
@@ -21,44 +21,45 @@ module es {
|
||||
return this.getbounds();
|
||||
}
|
||||
protected _areBoundsDirty: boolean = true;
|
||||
|
||||
public color: Color = Color.White;
|
||||
|
||||
public get renderLayer() {
|
||||
return this._renderLayer;
|
||||
}
|
||||
public set renderLayer(value: number) {
|
||||
this.setRenderLayer(value);
|
||||
}
|
||||
|
||||
|
||||
protected _renderLayer: number = 0;
|
||||
|
||||
|
||||
public onEntityTransformChanged(comp: transform.Component) {
|
||||
this._areBoundsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
public get localOffset() {
|
||||
return this._localOffset;
|
||||
}
|
||||
public set localOffset(value: es.Vector2) {
|
||||
this.setLocalOffset(value);
|
||||
}
|
||||
|
||||
|
||||
public setLocalOffset(offset: es.Vector2) {
|
||||
if (!this._localOffset.equals(offset)) {
|
||||
this._localOffset = offset;
|
||||
this._areBoundsDirty = true;
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public get isVisible() {
|
||||
return this._isVisible;
|
||||
}
|
||||
|
||||
|
||||
public set isVisible(value: boolean) {
|
||||
if (this._isVisible != value) {
|
||||
this._isVisible = value;
|
||||
|
||||
|
||||
if (this._isVisible) {
|
||||
this.onBecameVisible();
|
||||
} else {
|
||||
@@ -66,44 +67,44 @@ module es {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public debugRenderEnabled: boolean = true;
|
||||
|
||||
|
||||
protected _isVisible: boolean = false;
|
||||
protected _localOffset: es.Vector2 = new es.Vector2();
|
||||
|
||||
|
||||
public abstract render(batcher: IBatcher, camera: ICamera): void;
|
||||
|
||||
|
||||
protected onBecameVisible() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected onBecameInvisible() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public setRenderLayer(renderLayer: number): RenderableComponent {
|
||||
if (renderLayer != this._renderLayer) {
|
||||
let oldRenderLayer = this._renderLayer;
|
||||
this._renderLayer = renderLayer;
|
||||
|
||||
|
||||
if (this.entity != null && this.entity.scene != null)
|
||||
es.Core.scene.renderableComponents.updateRenderableRenderLayer(this, oldRenderLayer, this._renderLayer);
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public isVisibleFromCamera(cam: ICamera): boolean {
|
||||
this.isVisible = cam.bounds.intersects(this.bounds);
|
||||
|
||||
|
||||
return this.isVisible;
|
||||
}
|
||||
|
||||
|
||||
public debugRender(batcher: IBatcher) {
|
||||
if (!this.debugRenderEnabled)
|
||||
return;
|
||||
|
||||
|
||||
let collider = null;
|
||||
for (let i = 0; i < this.entity.components.buffer.length; i++) {
|
||||
let component = this.entity.components.buffer[i];
|
||||
@@ -112,14 +113,21 @@ module es {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (collider == null) {
|
||||
batcher.drawHollowRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height, new Color(255, 255, 0));
|
||||
batcher.end();
|
||||
}
|
||||
|
||||
|
||||
batcher.drawPixel(es.Vector2.add(this.entity.transform.position, this._localOffset), new Color(153, 50, 204), 4);
|
||||
batcher.end();
|
||||
}
|
||||
|
||||
public tweenColorTo(to: Color, duration: number) {
|
||||
const tween = Pool.obtain(RenderableColorTween);
|
||||
tween.setTarget(this);
|
||||
tween.initialize(tween, to, duration);
|
||||
return tween;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -491,6 +491,66 @@ module es {
|
||||
}
|
||||
}
|
||||
|
||||
public tweenPositionTo(to: Vector2, duration: number = 0.3): ITween<Vector2> {
|
||||
const tween = Pool.obtain(TransformVector2Tween);
|
||||
tween.setTargetAndType(this.transform, TransformTargetType.position);
|
||||
tween.initialize(tween, to, duration);
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public tweenLocalPositionTo(to: Vector2, duration = 0.3): ITween<Vector2> {
|
||||
const tween = Pool.obtain(TransformVector2Tween);
|
||||
tween.setTargetAndType(this.transform, TransformTargetType.localPosition);
|
||||
tween.initialize(tween, to, duration);
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public tweenScaleTo(to: Vector2, duration?: number);
|
||||
public tweenScaleTo(to: number, duration?: number);
|
||||
public tweenScaleTo(to: Vector2 | number, duration: number = 0.3) {
|
||||
if (typeof (to) == 'number') {
|
||||
return this.tweenScaleTo(new Vector2(to, to), duration);
|
||||
}
|
||||
|
||||
const tween = Pool.obtain(TransformVector2Tween);
|
||||
tween.setTargetAndType(this.transform, TransformTargetType.scale);
|
||||
tween.initialize(tween, to, duration);
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public tweenLocalScaleTo(to: Vector2, duration?);
|
||||
public tweenLocalScaleTo(to: number, duration?);
|
||||
public tweenLocalScaleTo(to: Vector2 | number, duration = 0.3) {
|
||||
if (typeof (to) == 'number') {
|
||||
return this.tweenLocalScaleTo(new Vector2(to, to), duration);
|
||||
}
|
||||
|
||||
const tween = Pool.obtain(TransformVector2Tween);
|
||||
tween.setTargetAndType(this.transform, TransformTargetType.localScale);
|
||||
tween.initialize(tween, to, duration);
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public tweenRotationDegreesTo(to: number, duration = 0.3) {
|
||||
const tween = Pool.obtain(TransformVector2Tween);
|
||||
tween.setTargetAndType(this.transform, TransformTargetType.rotationDegrees);
|
||||
tween.initialize(tween, new Vector2(to, to), duration);
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public tweenLocalRotationDegreesTo(to: number, duration = 0.3) {
|
||||
const tween = Pool.obtain(TransformVector2Tween);
|
||||
tween.setTargetAndType(this.transform, TransformTargetType.localRotationDegrees);
|
||||
tween.initialize(tween, new Vector2(to, to), duration);
|
||||
|
||||
return tween;
|
||||
}
|
||||
|
||||
public compareTo(other: Entity): number {
|
||||
let compare = this._updateOrder - other._updateOrder;
|
||||
if (compare == 0)
|
||||
|
||||
Reference in New Issue
Block a user