新增动画 移除不相关的库
This commit is contained in:
10
demo/.vscode/tasks.json
vendored
Normal file
10
demo/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": "0.1.0",
|
||||
"command": "egret",
|
||||
"isShellCommand": true,
|
||||
"showOutput": "silent",
|
||||
"args": [
|
||||
"build"
|
||||
],
|
||||
"problemMatcher": "$tsc"
|
||||
}
|
||||
2452
demo/libs/fairygui/fairygui.d.ts
vendored
2452
demo/libs/fairygui/fairygui.d.ts
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1
demo/libs/fairygui/fairygui.min.js
vendored
1
demo/libs/fairygui/fairygui.min.js
vendored
File diff suppressed because one or more lines are too long
65
demo/libs/framework/framework.d.ts
vendored
65
demo/libs/framework/framework.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
2
demo/libs/framework/framework.min.js
vendored
2
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
345
demo/resource/assets/isometric_grass_and_water.json
Normal file
345
demo/resource/assets/isometric_grass_and_water.json
Normal file
@@ -0,0 +1,345 @@
|
||||
{ "height":25,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"data":[24, 24, 23, 11, 19, 19, 12, 23, 24, 24, 23, 7, 2, 2, 1, 4, 2, 2, 3, 4, 4, 1, 3, 4, 1, 24, 23, 23, 14, 3, 3, 8, 12, 24, 24, 18, 4, 1, 3, 1, 3, 3, 4, 4, 1, 3, 1, 4, 3, 4, 11, 15, 15, 7, 1, 4, 3, 20, 23, 11, 7, 2, 1, 3, 1, 3, 4, 4, 3, 2, 2, 3, 4, 2, 1, 18, 4, 3, 2, 2, 4, 3, 8, 12, 18, 2, 4, 4, 3, 3, 1, 4, 2, 1, 4, 4, 4, 1, 1, 1, 14, 2, 1, 4, 2, 1, 4, 2, 8, 7, 5, 17, 6, 3, 3, 3, 4, 3, 4, 4, 3, 2, 4, 3, 4, 10, 6, 2, 1, 4, 4, 1, 3, 4, 3, 8, 12, 10, 6, 2, 1, 1, 1, 1, 2, 1, 4, 2, 1, 1, 24, 18, 1, 2, 4, 3, 3, 5, 6, 5, 13, 9, 11, 7, 3, 4, 1, 3, 1, 3, 4, 2, 4, 4, 4, 24, 14, 4, 2, 5, 6, 2, 8, 22, 9, 23, 24, 10, 6, 2, 1, 3, 1, 5, 6, 2, 3, 4, 4, 2, 19, 7, 3, 1, 8, 7, 4, 1, 8, 12, 24, 23, 23, 10, 17, 6, 3, 1, 8, 7, 1, 3, 3, 3, 1, 1, 2, 4, 2, 2, 3, 3, 4, 3, 20, 24, 23, 23, 23, 23, 18, 2, 2, 3, 1, 4, 4, 1, 1, 1, 3, 3, 5, 13, 6, 1, 2, 2, 5, 9, 23, 23, 24, 23, 24, 14, 1, 3, 1, 1, 3, 3, 4, 4, 4, 2, 4, 16, 24, 10, 6, 2, 4, 20, 23, 23, 24, 23, 23, 24, 14, 2, 4, 2, 4, 5, 6, 4, 3, 1, 3, 1, 20, 23, 24, 10, 6, 3, 8, 12, 24, 23, 23, 23, 24, 14, 1, 2, 1, 5, 9, 18, 4, 3, 4, 4, 2, 8, 12, 23, 24, 18, 4, 3, 16, 24, 24, 24, 23, 24, 18, 1, 3, 1, 16, 24, 14, 1, 3, 2, 4, 1, 2, 8, 12, 24, 14, 4, 1, 8, 15, 12, 24, 23, 11, 7, 2, 1, 2, 16, 23, 18, 1, 4, 2, 3, 4, 3, 2, 8, 19, 7, 2, 2, 3, 3, 8, 15, 19, 7, 3, 1, 2, 5, 9, 24, 14, 1, 2, 3, 2, 2, 1, 4, 4, 1, 2, 5, 6, 2, 2, 2, 1, 3, 4, 3, 5, 13, 9, 24, 24, 18, 4, 3, 4, 1, 4, 1, 3, 2, 5, 13, 9, 14, 3, 1, 3, 2, 4, 4, 5, 21, 19, 12, 24, 11, 7, 1, 2, 3, 2, 1, 3, 3, 3, 20, 23, 24, 18, 4, 4, 2, 3, 1, 1, 8, 7, 5, 9, 23, 18, 1, 3, 4, 2, 4, 2, 4, 1, 2, 8, 15, 19, 7, 4, 5, 6, 4, 2, 4, 5, 17, 9, 23, 11, 22, 13, 6, 4, 1, 3, 2, 2, 4, 4, 3, 2, 1, 4, 2, 8, 7, 4, 2, 3, 16, 24, 23, 11, 7, 16, 23, 18, 3, 1, 1, 3, 1, 2, 3, 3, 3, 4, 2, 1, 3, 2, 3, 4, 3, 8, 15, 15, 7, 4, 8, 19, 7, 3, 4, 1, 2, 3, 4, 1, 3, 4, 4, 4, 1, 4, 4, 3, 2, 3, 4, 1, 2, 4, 2, 1, 2, 2, 4, 1, 4, 2, 3, 2, 1, 4, 2, 2, 1, 2, 2, 2, 4, 3, 3, 2, 3, 3, 2, 3, 2, 4, 1, 3, 1, 1, 1, 1, 4, 1, 3, 3, 2, 1, 4, 2, 1, 3, 1, 3, 3, 4, 3, 4, 2, 1, 2, 3, 1, 1],
|
||||
"height":25,
|
||||
"id":1,
|
||||
"name":"Tile Layer 1",
|
||||
"opacity":1,
|
||||
"type":"tilelayer",
|
||||
"visible":true,
|
||||
"width":25,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":2,
|
||||
"nextobjectid":1,
|
||||
"orientation":"isometric",
|
||||
"renderorder":"right-down",
|
||||
"tiledversion":"1.2.1",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"columns":4,
|
||||
"firstgid":1,
|
||||
"grid":
|
||||
{
|
||||
"height":32,
|
||||
"orientation":"isometric",
|
||||
"width":64
|
||||
},
|
||||
"image":"isometric_grass_and_water.png",
|
||||
"imageheight":384,
|
||||
"imagewidth":256,
|
||||
"margin":0,
|
||||
"name":"isometric_grass_and_water",
|
||||
"spacing":0,
|
||||
"terrains":[
|
||||
{
|
||||
"name":"Grass",
|
||||
"tile":0
|
||||
},
|
||||
{
|
||||
"name":"Water",
|
||||
"tile":22
|
||||
}],
|
||||
"tilecount":24,
|
||||
"tileheight":64,
|
||||
"tileoffset":
|
||||
{
|
||||
"x":0,
|
||||
"y":16
|
||||
},
|
||||
"tiles":[
|
||||
{
|
||||
"id":0,
|
||||
"terrain":[0, 0, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":1,
|
||||
"terrain":[0, 0, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":2,
|
||||
"terrain":[0, 0, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":3,
|
||||
"terrain":[0, 0, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":4,
|
||||
"terrain":[0, 0, 0, 1]
|
||||
},
|
||||
{
|
||||
"id":5,
|
||||
"terrain":[0, 0, 1, 0]
|
||||
},
|
||||
{
|
||||
"id":6,
|
||||
"terrain":[1, 0, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":7,
|
||||
"terrain":[0, 1, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":8,
|
||||
"terrain":[0, 1, 1, 1]
|
||||
},
|
||||
{
|
||||
"id":9,
|
||||
"terrain":[1, 0, 1, 1]
|
||||
},
|
||||
{
|
||||
"id":10,
|
||||
"terrain":[1, 1, 1, 0]
|
||||
},
|
||||
{
|
||||
"id":11,
|
||||
"terrain":[1, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"id":12,
|
||||
"terrain":[0, 0, 1, 1]
|
||||
},
|
||||
{
|
||||
"id":13,
|
||||
"terrain":[1, 0, 1, 0]
|
||||
},
|
||||
{
|
||||
"id":14,
|
||||
"terrain":[1, 1, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":15,
|
||||
"terrain":[0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"id":16,
|
||||
"terrain":[0, 0, 1, 1]
|
||||
},
|
||||
{
|
||||
"id":17,
|
||||
"terrain":[1, 0, 1, 0]
|
||||
},
|
||||
{
|
||||
"id":18,
|
||||
"terrain":[1, 1, 0, 0]
|
||||
},
|
||||
{
|
||||
"id":19,
|
||||
"terrain":[0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"id":20,
|
||||
"terrain":[0, 1, 1, 0]
|
||||
},
|
||||
{
|
||||
"id":21,
|
||||
"terrain":[1, 0, 0, 1]
|
||||
},
|
||||
{
|
||||
"id":22,
|
||||
"terrain":[1, 1, 1, 1]
|
||||
},
|
||||
{
|
||||
"id":23,
|
||||
"terrain":[1, 1, 1, 1]
|
||||
}],
|
||||
"tilewidth":64,
|
||||
"wangsets":[
|
||||
{
|
||||
"cornercolors":[
|
||||
{
|
||||
"color":"#8ab022",
|
||||
"name":"Grass",
|
||||
"probability":1,
|
||||
"tile":0
|
||||
},
|
||||
{
|
||||
"color":"#378dc2",
|
||||
"name":"Water",
|
||||
"probability":1,
|
||||
"tile":23
|
||||
}],
|
||||
"edgecolors":[],
|
||||
"name":"Grass and Water",
|
||||
"tile":15,
|
||||
"wangtiles":[
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":0,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":1,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":2,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":3,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":4,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 2, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":5,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 2, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":6,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 1, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":7,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 1, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":8,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 2, 0, 2, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":9,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 2, 0, 2, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":10,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 1, 0, 2, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":11,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 2, 0, 1, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":12,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 2, 0, 2, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":13,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 2, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":14,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 1, 0, 1, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":15,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 2, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":16,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 2, 0, 2, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":17,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 1, 0, 2, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":18,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 1, 0, 1, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":19,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 2, 0, 1, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":20,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 1, 0, 2, 0, 1]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":21,
|
||||
"vflip":false,
|
||||
"wangid":[0, 1, 0, 2, 0, 1, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":22,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 2, 0, 2, 0, 2]
|
||||
},
|
||||
{
|
||||
"dflip":false,
|
||||
"hflip":false,
|
||||
"tileid":23,
|
||||
"vflip":false,
|
||||
"wangid":[0, 2, 0, 2, 0, 2, 0, 2]
|
||||
}]
|
||||
}]
|
||||
}],
|
||||
"tilewidth":64,
|
||||
"type":"map",
|
||||
"version":1.2,
|
||||
"width":25
|
||||
}
|
||||
BIN
demo/resource/assets/isometric_grass_and_water.png
Normal file
BIN
demo/resource/assets/isometric_grass_and_water.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"groups": [
|
||||
{
|
||||
"keys": "checkbox_select_disabled_png,checkbox_select_down_png,checkbox_select_up_png,checkbox_unselect_png,selected_png,border_png,header_png,radiobutton_select_disabled_png,radiobutton_select_down_png,radiobutton_select_up_png,radiobutton_unselect_png,roundthumb_png,thumb_png,track_png,tracklight_png,handle_png,off_png,on_png,button_down_png,button_up_png,thumb_pb_png,track_pb_png,track_sb_png,bg_jpg,egret_icon_png,description_json",
|
||||
"keys": "checkbox_select_disabled_png,checkbox_select_down_png,checkbox_select_up_png,checkbox_unselect_png,selected_png,border_png,header_png,radiobutton_select_disabled_png,radiobutton_select_down_png,radiobutton_select_up_png,radiobutton_unselect_png,roundthumb_png,thumb_png,track_png,tracklight_png,handle_png,off_png,on_png,button_down_png,button_up_png,thumb_pb_png,track_pb_png,track_sb_png,bg_jpg,egret_icon_png,description_json,isometric_grass_and_water_json,isometric_grass_and_water_png",
|
||||
"name": "preload"
|
||||
}
|
||||
],
|
||||
@@ -135,6 +135,16 @@
|
||||
"name": "description_json",
|
||||
"type": "json",
|
||||
"url": "config/description.json"
|
||||
},
|
||||
{
|
||||
"name": "isometric_grass_and_water_json",
|
||||
"type": "json",
|
||||
"url": "assets/isometric_grass_and_water.json"
|
||||
},
|
||||
{
|
||||
"name": "isometric_grass_and_water_png",
|
||||
"type": "image",
|
||||
"url": "assets/isometric_grass_and_water.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
65
source/bin/framework.d.ts
vendored
65
source/bin/framework.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
2452
source/lib/fairygui.d.ts
vendored
2452
source/lib/fairygui.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,8 @@ abstract class Component extends egret.DisplayObjectContainer {
|
||||
public entity: Entity;
|
||||
private _enabled: boolean = true;
|
||||
public updateInterval: number = 1;
|
||||
/** 允许用户为实体存入信息 */
|
||||
public userData: any;
|
||||
|
||||
public get enabled(){
|
||||
return this.entity ? this.entity.enabled && this._enabled : this._enabled;
|
||||
|
||||
9
source/src/ECS/Components/SpriteAnimation.ts
Normal file
9
source/src/ECS/Components/SpriteAnimation.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
class SpriteAnimation {
|
||||
public readonly sprites: Sprite[];
|
||||
public readonly frameRate: number;
|
||||
|
||||
constructor(sprites: Sprite[], frameRate: number){
|
||||
this.sprites = sprites;
|
||||
this.frameRate = frameRate;
|
||||
}
|
||||
}
|
||||
142
source/src/ECS/Components/SpriteAnimator.ts
Normal file
142
source/src/ECS/Components/SpriteAnimator.ts
Normal file
@@ -0,0 +1,142 @@
|
||||
///<reference path="./SpriteRenderer.ts" />
|
||||
class SpriteAnimator extends SpriteRenderer {
|
||||
/** 在动画完成时触发,包括动画名称; */
|
||||
public onAnimationCompletedEvent: Function;
|
||||
/** 动画播放速度 */
|
||||
public speed = 1;
|
||||
/** 动画的当前状态 */
|
||||
public animationState = State.none;
|
||||
/** 当前动画 */
|
||||
public currentAnimation: SpriteAnimation;
|
||||
/** 当前动画的名称 */
|
||||
public currentAnimationName: string;
|
||||
/** 当前动画的精灵数组中当前帧的索引 */
|
||||
public currentFrame: number;
|
||||
/** 检查当前动画是否正在运行 */
|
||||
public get isRunning(): boolean{
|
||||
return this.animationState == State.running;
|
||||
}
|
||||
|
||||
private _animations: Map<string, SpriteAnimation> = new Map<string, SpriteAnimation>();
|
||||
private _elapsedTime: number = 0;
|
||||
private _loopMode: LoopMode;
|
||||
|
||||
constructor(sprite?: Sprite){
|
||||
super();
|
||||
|
||||
if (sprite) this.setSprite(sprite);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个SpriteAnimation
|
||||
* @param name
|
||||
* @param animation
|
||||
*/
|
||||
public addAnimation(name: string, animation: SpriteAnimation): SpriteAnimator{
|
||||
if (!this.sprite && animation.sprites.length > 0)
|
||||
this.setSprite(animation.sprites[0]);
|
||||
this._animations[name] = animation;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以给定的名称放置动画。如果没有指定循环模式,则默认为循环
|
||||
* @param name
|
||||
* @param loopMode
|
||||
*/
|
||||
public play(name: string, loopMode: 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查动画是否正在播放(即动画是活动的)。它可能仍然处于暂停状态)
|
||||
* @param name
|
||||
*/
|
||||
public isAnimationActive(name: string): boolean{
|
||||
return this.currentAnimation && this.currentAnimationName == name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 暂停动画
|
||||
*/
|
||||
public pause(){
|
||||
this.animationState = State.paused;
|
||||
}
|
||||
|
||||
/**
|
||||
* 继续动画
|
||||
*/
|
||||
public unPause(){
|
||||
this.animationState = State.running;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前动画并将其设为null
|
||||
*/
|
||||
public stop(){
|
||||
this.currentAnimation = null;
|
||||
this.currentAnimationName = null;
|
||||
this.currentFrame = 0;
|
||||
this.animationState = State.none;
|
||||
}
|
||||
|
||||
public update(){
|
||||
if (this.animationState != State.running || !this.currentAnimation) return;
|
||||
|
||||
let animation = this.currentAnimation;
|
||||
let secondsPerFrame = 1 / (animation.frameRate * this.speed);
|
||||
let iterationDuration = secondsPerFrame * animation.sprites.length;
|
||||
|
||||
this._elapsedTime += Time.deltaTime;
|
||||
let 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;
|
||||
}
|
||||
|
||||
// 弄清楚我们在哪个坐标系上
|
||||
let i = Math.floor(time / secondsPerFrame);
|
||||
let n = animation.sprites.length;
|
||||
if (n > 2 && (this._loopMode == LoopMode.pingPong || this._loopMode == LoopMode.pingPongOnce)){
|
||||
// pingpong
|
||||
let maxIndex = n - 1;
|
||||
this.currentFrame = maxIndex - Math.abs(maxIndex - i % (maxIndex * 2));
|
||||
}else{
|
||||
this.currentFrame = i % n;
|
||||
}
|
||||
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
}
|
||||
}
|
||||
|
||||
enum LoopMode {
|
||||
/** 在一个循环序列[A][B][C][A][B][C][A][B][C]... */
|
||||
loop,
|
||||
/** [A][B][C]然后暂停,设置时间为0 [A] */
|
||||
once,
|
||||
/** [A][B][C]。当它到达终点时,它会继续播放最后一帧,并且不会停止播放 */
|
||||
clampForever,
|
||||
/** 以一个乒乓循环的方式永远播放这个序列 [A][B][C][B][A][B][C][B]... */
|
||||
pingPong,
|
||||
/** 将顺序向前播放一次,然后返回到开始[A][B][C][B][A],然后暂停并设置时间为0 */
|
||||
pingPongOnce,
|
||||
}
|
||||
|
||||
enum State {
|
||||
none,
|
||||
running,
|
||||
paused,
|
||||
completed,
|
||||
}
|
||||
@@ -15,6 +15,14 @@ class SpriteRenderer extends RenderableComponent {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/** 应该由这个精灵显示的精灵。当设置时,精灵的原点也被设置为匹配精灵.origin。 */
|
||||
public get sprite(): Sprite{
|
||||
return this._sprite;
|
||||
}
|
||||
/** 应该由这个精灵显示的精灵。当设置时,精灵的原点也被设置为匹配精灵.origin。 */
|
||||
public set sprite(value: Sprite){
|
||||
this.setSprite(value);
|
||||
}
|
||||
|
||||
public setSprite(sprite: Sprite): SpriteRenderer{
|
||||
this.removeChildren();
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
///<reference path="./BaseView.ts" />
|
||||
/** 用于承载fui界面 */
|
||||
class BaseFuiView extends BaseView {
|
||||
/** 界面名称 */
|
||||
protected _name: string;
|
||||
|
||||
constructor(name: string){
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/** 用于表示单例类 */
|
||||
class BaseSingle {
|
||||
private static _instance: any;
|
||||
|
||||
public static getInstance<T>(): T {
|
||||
if (this._instance == null) {
|
||||
this._instance = new this();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
/**清除fgui元素 */
|
||||
protected clearFuiObj(obj: fairygui.GObject): boolean {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/** 所有视图的基类 */
|
||||
class BaseView extends egret.DisplayObjectContainer {
|
||||
/** 界面数据 */
|
||||
protected _data: any;
|
||||
/** 在打开界面前触发 */
|
||||
protected init(){
|
||||
|
||||
}
|
||||
|
||||
/** 窗口打开时触发 */
|
||||
public show(data?: any) {
|
||||
|
||||
}
|
||||
|
||||
/** 刷新界面数据 由mvc控制 */
|
||||
public refreshData(data?: any){
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
/** 刷新界面逻辑 */
|
||||
public refreshView(){
|
||||
|
||||
}
|
||||
|
||||
/** 关闭窗口 */
|
||||
public close() {
|
||||
|
||||
}
|
||||
|
||||
/** 销毁窗口 */
|
||||
public destroy(){
|
||||
if (this.parent){
|
||||
this.parent.removeChild(this);
|
||||
}
|
||||
|
||||
/** 循环删除此界面下所有节点 */
|
||||
while (this.numChildren > 0) {
|
||||
this.removeChildAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
class ViewManager extends BaseSingle {
|
||||
private _openDic: BaseFuiView[] = [];
|
||||
|
||||
/**
|
||||
* 刷新界面
|
||||
* @param viewClass 界面类型
|
||||
* @param data 界面数据
|
||||
*/
|
||||
public refreshView(viewClass: any, data?: any){
|
||||
let view = this.getView<BaseFuiView>(viewClass);
|
||||
|
||||
if (view){
|
||||
/** 压入数据 */
|
||||
view.refreshData(data);
|
||||
/** 执行刷新逻辑 */
|
||||
view.refreshView();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开界面
|
||||
* @param viewClass 界面类型
|
||||
* @param data 界面数据
|
||||
* @param complete 界面加载完成回调
|
||||
*/
|
||||
public openView(viewClass: any, data?: any, complete?: Function){
|
||||
let newView = this.getView<BaseFuiView>(viewClass);
|
||||
if (!newView){
|
||||
newView = new viewClass();
|
||||
}
|
||||
|
||||
/** 如果界面已打开 则执行刷新界面 */
|
||||
if (this.existView(viewClass)){
|
||||
newView.refreshData(data);
|
||||
newView.refreshView();
|
||||
return;
|
||||
}
|
||||
|
||||
this._openDic.push(newView);
|
||||
// TODO: 加载资源
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取界面 可能为null
|
||||
* @param viewClass 界面类型
|
||||
*/
|
||||
public getView<T>(viewClass: any): T {
|
||||
let result: any = this._openDic.firstOrDefault(a => {
|
||||
return a instanceof viewClass;
|
||||
});
|
||||
|
||||
return result as T;
|
||||
}
|
||||
|
||||
/**
|
||||
* 界面是否存在
|
||||
* @param viewClass 界面类型
|
||||
*/
|
||||
public existView(viewClass: any): boolean {
|
||||
return this._openDic.findIndex(a => {
|
||||
return a instanceof viewClass;
|
||||
}) != -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user