新增动画 移除不相关的库

This commit is contained in:
yhh
2020-07-03 16:45:52 +08:00
parent f36a1cdb27
commit c3c9181400
22 changed files with 831 additions and 24208 deletions

View File

@@ -143,6 +143,7 @@ declare abstract class Component extends egret.DisplayObjectContainer {
entity: Entity;
private _enabled;
updateInterval: number;
userData: any;
enabled: boolean;
setEnabled(isEnabled: boolean): this;
initialize(): void;
@@ -318,12 +319,18 @@ declare class Sprite {
readonly uvs: Rectangle;
constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
}
declare class SpriteAnimation {
readonly sprites: Sprite[];
readonly frameRate: number;
constructor(sprites: Sprite[], frameRate: number);
}
declare class SpriteRenderer extends RenderableComponent {
private _origin;
private _bitmap;
private _sprite;
origin: Vector2;
setOrigin(origin: Vector2): this;
sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer;
setColor(color: number): SpriteRenderer;
isVisibleFromCamera(camera: Camera): boolean;
@@ -331,6 +338,39 @@ declare class SpriteRenderer extends RenderableComponent {
onRemovedFromEntity(): void;
reset(): void;
}
declare class SpriteAnimator extends SpriteRenderer {
onAnimationCompletedEvent: Function;
speed: number;
animationState: State;
currentAnimation: SpriteAnimation;
currentAnimationName: string;
currentFrame: number;
readonly isRunning: boolean;
private _animations;
private _elapsedTime;
private _loopMode;
constructor(sprite?: Sprite);
addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator;
play(name: string, loopMode?: LoopMode): void;
isAnimationActive(name: string): boolean;
pause(): void;
unPause(): void;
stop(): void;
update(): void;
}
declare enum LoopMode {
loop = 0,
once = 1,
clampForever = 2,
pingPong = 3,
pingPongOnce = 4
}
declare enum State {
none = 0,
running = 1,
paused = 2,
completed = 3
}
interface ITriggerListener {
onTriggerEnter(other: Collider, local: Collider): any;
onTriggerExit(other: Collider, local: Collider): any;
@@ -644,31 +684,6 @@ declare class WindTransition extends SceneTransition {
constructor(sceneLoadAction: Function);
onBeginTransition(): Promise<void>;
}
declare class BaseView extends egret.DisplayObjectContainer {
protected _data: any;
protected init(): void;
show(data?: any): void;
refreshData(data?: any): void;
refreshView(): void;
close(): void;
destroy(): void;
}
declare class BaseFuiView extends BaseView {
protected _name: string;
constructor(name: string);
}
declare class BaseSingle {
private static _instance;
static getInstance<T>(): T;
protected clearFuiObj(obj: fairygui.GObject): boolean;
}
declare class ViewManager extends BaseSingle {
private _openDic;
refreshView(viewClass: any, data?: any): void;
openView(viewClass: any, data?: any, complete?: Function): void;
getView<T>(viewClass: any): T;
existView(viewClass: any): boolean;
}
declare class Flags {
static isFlagSet(self: number, flag: number): boolean;
static isUnshiftedFlagSet(self: number, flag: number): boolean;

View File

@@ -1566,6 +1566,13 @@ var Sprite = (function () {
}
return Sprite;
}());
var SpriteAnimation = (function () {
function SpriteAnimation(sprites, frameRate) {
this.sprites = sprites;
this.frameRate = frameRate;
}
return SpriteAnimation;
}());
var SpriteRenderer = (function (_super) {
__extends(SpriteRenderer, _super);
function SpriteRenderer() {
@@ -1587,6 +1594,16 @@ var SpriteRenderer = (function (_super) {
}
return this;
};
Object.defineProperty(SpriteRenderer.prototype, "sprite", {
get: function () {
return this._sprite;
},
set: function (value) {
this.setSprite(value);
},
enumerable: true,
configurable: true
});
SpriteRenderer.prototype.setSprite = function (sprite) {
this.removeChildren();
this._sprite = sprite;
@@ -1627,6 +1644,100 @@ var SpriteRenderer = (function (_super) {
};
return SpriteRenderer;
}(RenderableComponent));
var SpriteAnimator = (function (_super) {
__extends(SpriteAnimator, _super);
function SpriteAnimator(sprite) {
var _this = _super.call(this) || this;
_this.speed = 1;
_this.animationState = State.none;
_this._animations = new Map();
_this._elapsedTime = 0;
if (sprite)
_this.setSprite(sprite);
return _this;
}
Object.defineProperty(SpriteAnimator.prototype, "isRunning", {
get: function () {
return this.animationState == State.running;
},
enumerable: true,
configurable: true
});
SpriteAnimator.prototype.addAnimation = function (name, animation) {
if (!this.sprite && animation.sprites.length > 0)
this.setSprite(animation.sprites[0]);
this._animations[name] = animation;
return this;
};
SpriteAnimator.prototype.play = function (name, loopMode) {
if (loopMode === void 0) { loopMode = null; }
this.currentAnimation = this._animations[name];
this.currentAnimationName = name;
this.currentFrame = 0;
this.animationState = State.running;
this.sprite = this.currentAnimation.sprites[0];
this._elapsedTime = 0;
this._loopMode = loopMode ? loopMode : LoopMode.loop;
};
SpriteAnimator.prototype.isAnimationActive = function (name) {
return this.currentAnimation && this.currentAnimationName == name;
};
SpriteAnimator.prototype.pause = function () {
this.animationState = State.paused;
};
SpriteAnimator.prototype.unPause = function () {
this.animationState = State.running;
};
SpriteAnimator.prototype.stop = function () {
this.currentAnimation = null;
this.currentAnimationName = null;
this.currentFrame = 0;
this.animationState = State.none;
};
SpriteAnimator.prototype.update = function () {
if (this.animationState != State.running || !this.currentAnimation)
return;
var animation = this.currentAnimation;
var secondsPerFrame = 1 / (animation.frameRate * this.speed);
var iterationDuration = secondsPerFrame * animation.sprites.length;
this._elapsedTime += Time.deltaTime;
var time = Math.abs(this._elapsedTime);
if (this._loopMode == LoopMode.once && time > iterationDuration ||
this._loopMode == LoopMode.pingPongOnce && time > iterationDuration * 2) {
this.animationState = State.completed;
this._elapsedTime = 0;
this.currentFrame = 0;
this.sprite = animation.sprites[this.currentFrame];
return;
}
var i = Math.floor(time / secondsPerFrame);
var n = animation.sprites.length;
if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)) {
var maxIndex = n - 1;
this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2));
}
else {
this.currentFrame = i % n;
}
this.sprite = animation.sprites[this.currentFrame];
};
return SpriteAnimator;
}(SpriteRenderer));
var LoopMode;
(function (LoopMode) {
LoopMode[LoopMode["loop"] = 0] = "loop";
LoopMode[LoopMode["once"] = 1] = "once";
LoopMode[LoopMode["clampForever"] = 2] = "clampForever";
LoopMode[LoopMode["pingPong"] = 3] = "pingPong";
LoopMode[LoopMode["pingPongOnce"] = 4] = "pingPongOnce";
})(LoopMode || (LoopMode = {}));
var State;
(function (State) {
State[State["none"] = 0] = "none";
State[State["running"] = 1] = "running";
State[State["paused"] = 2] = "paused";
State[State["completed"] = 3] = "completed";
})(State || (State = {}));
var Mover = (function (_super) {
__extends(Mover, _super);
function Mover() {
@@ -2968,103 +3079,6 @@ var WindTransition = (function (_super) {
};
return WindTransition;
}(SceneTransition));
var BaseView = (function (_super) {
__extends(BaseView, _super);
function BaseView() {
return _super !== null && _super.apply(this, arguments) || this;
}
BaseView.prototype.init = function () {
};
BaseView.prototype.show = function (data) {
};
BaseView.prototype.refreshData = function (data) {
this._data = data;
};
BaseView.prototype.refreshView = function () {
};
BaseView.prototype.close = function () {
};
BaseView.prototype.destroy = function () {
if (this.parent) {
this.parent.removeChild(this);
}
while (this.numChildren > 0) {
this.removeChildAt(0);
}
};
return BaseView;
}(egret.DisplayObjectContainer));
var BaseFuiView = (function (_super) {
__extends(BaseFuiView, _super);
function BaseFuiView(name) {
var _this = _super.call(this) || this;
_this.name = name;
return _this;
}
return BaseFuiView;
}(BaseView));
var BaseSingle = (function () {
function BaseSingle() {
}
BaseSingle.getInstance = function () {
if (this._instance == null) {
this._instance = new this();
}
return this._instance;
};
BaseSingle.prototype.clearFuiObj = function (obj) {
if (obj) {
egret.Tween.removeTweens(obj.displayObject);
if (obj.displayObject && obj.displayObject.parent) {
obj.displayObject.parent.removeChild(obj.displayObject);
}
obj.dispose();
obj = null;
return true;
}
return false;
};
return BaseSingle;
}());
var ViewManager = (function (_super) {
__extends(ViewManager, _super);
function ViewManager() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._openDic = [];
return _this;
}
ViewManager.prototype.refreshView = function (viewClass, data) {
var view = this.getView(viewClass);
if (view) {
view.refreshData(data);
view.refreshView();
}
};
ViewManager.prototype.openView = function (viewClass, data, complete) {
var newView = this.getView(viewClass);
if (!newView) {
newView = new viewClass();
}
if (this.existView(viewClass)) {
newView.refreshData(data);
newView.refreshView();
return;
}
this._openDic.push(newView);
};
ViewManager.prototype.getView = function (viewClass) {
var result = this._openDic.firstOrDefault(function (a) {
return a instanceof viewClass;
});
return result;
};
ViewManager.prototype.existView = function (viewClass) {
return this._openDic.findIndex(function (a) {
return a instanceof viewClass;
}) != -1;
};
return ViewManager;
}(BaseSingle));
var Flags = (function () {
function Flags() {
}

File diff suppressed because one or more lines are too long