mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-04 06:39:09 +08:00
[ts] Added AssetManager subclasses for WebGL and Canvas backend
This commit is contained in:
parent
61c5c36774
commit
22cc0993f7
56
spine-ts/build/spine-all.d.ts
vendored
56
spine-ts/build/spine-all.d.ts
vendored
@ -1,3 +1,29 @@
|
|||||||
|
declare module spine {
|
||||||
|
class AssetManager implements Disposable {
|
||||||
|
private _textureLoader;
|
||||||
|
private _assets;
|
||||||
|
private _errors;
|
||||||
|
private _toLoad;
|
||||||
|
private _loaded;
|
||||||
|
constructor(textureLoader: (image: HTMLImageElement) => any);
|
||||||
|
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
|
||||||
|
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
|
||||||
|
get(path: string): any;
|
||||||
|
remove(path: string): void;
|
||||||
|
removeAll(): void;
|
||||||
|
isLoadingComplete(): boolean;
|
||||||
|
toLoad(): number;
|
||||||
|
loaded(): number;
|
||||||
|
dispose(): void;
|
||||||
|
hasErrors(): boolean;
|
||||||
|
errors(): Map<string>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module spine.canvas {
|
||||||
|
class AssetManager extends spine.AssetManager {
|
||||||
|
constructor();
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module spine {
|
declare module spine {
|
||||||
abstract class Texture {
|
abstract class Texture {
|
||||||
protected _image: HTMLImageElement;
|
protected _image: HTMLImageElement;
|
||||||
@ -50,8 +76,8 @@ declare module spine.canvas {
|
|||||||
class SkeletonRenderer {
|
class SkeletonRenderer {
|
||||||
static QUAD_TRIANGLES: number[];
|
static QUAD_TRIANGLES: number[];
|
||||||
private _ctx;
|
private _ctx;
|
||||||
useTriangleRendering: boolean;
|
triangleRendering: boolean;
|
||||||
useDebugRendering: boolean;
|
debugRendering: boolean;
|
||||||
constructor(context: CanvasRenderingContext2D);
|
constructor(context: CanvasRenderingContext2D);
|
||||||
draw(skeleton: Skeleton): void;
|
draw(skeleton: Skeleton): void;
|
||||||
private drawImages(skeleton);
|
private drawImages(skeleton);
|
||||||
@ -295,27 +321,6 @@ declare module spine {
|
|||||||
getMix(from: Animation, to: Animation): number;
|
getMix(from: Animation, to: Animation): number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module spine {
|
|
||||||
class AssetManager implements Disposable {
|
|
||||||
private _textureLoader;
|
|
||||||
private _assets;
|
|
||||||
private _errors;
|
|
||||||
private _toLoad;
|
|
||||||
private _loaded;
|
|
||||||
constructor(textureLoader: (image: HTMLImageElement) => any);
|
|
||||||
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
|
|
||||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
|
|
||||||
get(path: string): any;
|
|
||||||
remove(path: string): void;
|
|
||||||
removeAll(): void;
|
|
||||||
isLoadingComplete(): boolean;
|
|
||||||
toLoad(): number;
|
|
||||||
loaded(): number;
|
|
||||||
dispose(): void;
|
|
||||||
hasErrors(): boolean;
|
|
||||||
errors(): Map<string>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module spine {
|
declare module spine {
|
||||||
enum BlendMode {
|
enum BlendMode {
|
||||||
Normal = 0,
|
Normal = 0,
|
||||||
@ -894,6 +899,11 @@ declare module spine {
|
|||||||
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
|
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module spine.webgl {
|
||||||
|
class AssetManager extends spine.AssetManager {
|
||||||
|
constructor(gl: WebGLRenderingContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module spine.webgl {
|
declare module spine.webgl {
|
||||||
class GLTexture extends Texture implements Disposable {
|
class GLTexture extends Texture implements Disposable {
|
||||||
private _gl;
|
private _gl;
|
||||||
|
|||||||
@ -1,4 +1,120 @@
|
|||||||
var spine;
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var AssetManager = (function () {
|
||||||
|
function AssetManager(textureLoader) {
|
||||||
|
this._assets = {};
|
||||||
|
this._errors = {};
|
||||||
|
this._toLoad = 0;
|
||||||
|
this._loaded = 0;
|
||||||
|
this._textureLoader = textureLoader;
|
||||||
|
}
|
||||||
|
AssetManager.prototype.loadText = function (path, success, error) {
|
||||||
|
var _this = this;
|
||||||
|
if (success === void 0) { success = null; }
|
||||||
|
if (error === void 0) { error = null; }
|
||||||
|
this._toLoad++;
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
request.onreadystatechange = function () {
|
||||||
|
if (request.readyState == XMLHttpRequest.DONE) {
|
||||||
|
if (request.status >= 200 && request.status < 300) {
|
||||||
|
if (success)
|
||||||
|
success(path, request.responseText);
|
||||||
|
_this._assets[path] = request.responseText;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (error)
|
||||||
|
error(path, "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText);
|
||||||
|
_this._errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
|
||||||
|
}
|
||||||
|
_this._toLoad--;
|
||||||
|
_this._loaded++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
request.open("GET", path, true);
|
||||||
|
request.send();
|
||||||
|
};
|
||||||
|
AssetManager.prototype.loadTexture = function (path, success, error) {
|
||||||
|
var _this = this;
|
||||||
|
if (success === void 0) { success = null; }
|
||||||
|
if (error === void 0) { error = null; }
|
||||||
|
this._toLoad++;
|
||||||
|
var img = new Image();
|
||||||
|
img.src = path;
|
||||||
|
img.onload = function (ev) {
|
||||||
|
if (success)
|
||||||
|
success(path, img);
|
||||||
|
var texture = _this._textureLoader(img);
|
||||||
|
_this._assets[path] = texture;
|
||||||
|
_this._toLoad--;
|
||||||
|
_this._loaded++;
|
||||||
|
};
|
||||||
|
img.onerror = function (ev) {
|
||||||
|
if (error)
|
||||||
|
error(path, "Couldn't load image " + path);
|
||||||
|
_this._errors[path] = "Couldn't load image " + path;
|
||||||
|
_this._toLoad--;
|
||||||
|
_this._loaded++;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
AssetManager.prototype.get = function (path) {
|
||||||
|
return this._assets[path];
|
||||||
|
};
|
||||||
|
AssetManager.prototype.remove = function (path) {
|
||||||
|
var asset = this._assets[path];
|
||||||
|
if (asset.dispose)
|
||||||
|
asset.dispose();
|
||||||
|
this._assets[path] = null;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.removeAll = function () {
|
||||||
|
for (var key in this._assets) {
|
||||||
|
var asset = this._assets[key];
|
||||||
|
if (asset.dispose)
|
||||||
|
asset.dispose();
|
||||||
|
}
|
||||||
|
this._assets = {};
|
||||||
|
};
|
||||||
|
AssetManager.prototype.isLoadingComplete = function () {
|
||||||
|
return this._toLoad == 0;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.toLoad = function () {
|
||||||
|
return this._toLoad;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.loaded = function () {
|
||||||
|
return this._loaded;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.dispose = function () {
|
||||||
|
this.removeAll();
|
||||||
|
};
|
||||||
|
AssetManager.prototype.hasErrors = function () {
|
||||||
|
return Object.keys(this._errors).length > 0;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.errors = function () {
|
||||||
|
return this._errors;
|
||||||
|
};
|
||||||
|
return AssetManager;
|
||||||
|
}());
|
||||||
|
spine.AssetManager = AssetManager;
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var __extends = (this && this.__extends) || function (d, b) {
|
||||||
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var canvas;
|
||||||
|
(function (canvas) {
|
||||||
|
var AssetManager = (function (_super) {
|
||||||
|
__extends(AssetManager, _super);
|
||||||
|
function AssetManager() {
|
||||||
|
_super.call(this, function (image) { return new spine.canvas.CanvasTexture(image); });
|
||||||
|
}
|
||||||
|
return AssetManager;
|
||||||
|
}(spine.AssetManager));
|
||||||
|
canvas.AssetManager = AssetManager;
|
||||||
|
})(canvas = spine.canvas || (spine.canvas = {}));
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var Texture = (function () {
|
var Texture = (function () {
|
||||||
function Texture(image) {
|
function Texture(image) {
|
||||||
@ -64,11 +180,6 @@ var spine;
|
|||||||
}());
|
}());
|
||||||
spine.TextureRegion = TextureRegion;
|
spine.TextureRegion = TextureRegion;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var __extends = (this && this.__extends) || function (d, b) {
|
|
||||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
||||||
function __() { this.constructor = d; }
|
|
||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
||||||
};
|
|
||||||
var spine;
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var canvas;
|
var canvas;
|
||||||
@ -92,12 +203,12 @@ var spine;
|
|||||||
(function (canvas) {
|
(function (canvas) {
|
||||||
var SkeletonRenderer = (function () {
|
var SkeletonRenderer = (function () {
|
||||||
function SkeletonRenderer(context) {
|
function SkeletonRenderer(context) {
|
||||||
this.useTriangleRendering = false;
|
this.triangleRendering = false;
|
||||||
this.useDebugRendering = false;
|
this.debugRendering = false;
|
||||||
this._ctx = context;
|
this._ctx = context;
|
||||||
}
|
}
|
||||||
SkeletonRenderer.prototype.draw = function (skeleton) {
|
SkeletonRenderer.prototype.draw = function (skeleton) {
|
||||||
if (this.useTriangleRendering)
|
if (this.triangleRendering)
|
||||||
this.drawTriangles(skeleton);
|
this.drawTriangles(skeleton);
|
||||||
else
|
else
|
||||||
this.drawImages(skeleton);
|
this.drawImages(skeleton);
|
||||||
@ -105,7 +216,7 @@ var spine;
|
|||||||
SkeletonRenderer.prototype.drawImages = function (skeleton) {
|
SkeletonRenderer.prototype.drawImages = function (skeleton) {
|
||||||
var ctx = this._ctx;
|
var ctx = this._ctx;
|
||||||
var drawOrder = skeleton.drawOrder;
|
var drawOrder = skeleton.drawOrder;
|
||||||
if (this.useDebugRendering)
|
if (this.debugRendering)
|
||||||
ctx.strokeStyle = "green";
|
ctx.strokeStyle = "green";
|
||||||
for (var i = 0, n = drawOrder.length; i < n; i++) {
|
for (var i = 0, n = drawOrder.length; i < n; i++) {
|
||||||
var slot = drawOrder[i];
|
var slot = drawOrder[i];
|
||||||
@ -141,7 +252,7 @@ var spine;
|
|||||||
else {
|
else {
|
||||||
ctx.drawImage(image, region.x, region.y, region.width, region.height, 0, 0, w, h);
|
ctx.drawImage(image, region.x, region.y, region.width, region.height, 0, 0, w, h);
|
||||||
}
|
}
|
||||||
if (this.useDebugRendering)
|
if (this.debugRendering)
|
||||||
ctx.strokeRect(0, 0, w, h);
|
ctx.strokeRect(0, 0, w, h);
|
||||||
ctx.rotate(-rotation);
|
ctx.rotate(-rotation);
|
||||||
ctx.translate(-x, -y);
|
ctx.translate(-x, -y);
|
||||||
@ -184,7 +295,7 @@ var spine;
|
|||||||
var x1 = vertices[t2], y1 = vertices[t2 + 1], u1 = vertices[t2 + 6], v1 = vertices[t2 + 7];
|
var x1 = vertices[t2], y1 = vertices[t2 + 1], u1 = vertices[t2 + 6], v1 = vertices[t2 + 7];
|
||||||
var x2 = vertices[t3], y2 = vertices[t3 + 1], u2 = vertices[t3 + 6], v2 = vertices[t3 + 7];
|
var x2 = vertices[t3], y2 = vertices[t3 + 1], u2 = vertices[t3 + 6], v2 = vertices[t3 + 7];
|
||||||
this.drawTriangle(texture, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
|
this.drawTriangle(texture, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
|
||||||
if (this.useDebugRendering) {
|
if (this.debugRendering) {
|
||||||
ctx.strokeStyle = "green";
|
ctx.strokeStyle = "green";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(x0, y0);
|
ctx.moveTo(x0, y0);
|
||||||
@ -1215,103 +1326,6 @@ var spine;
|
|||||||
spine.AnimationStateData = AnimationStateData;
|
spine.AnimationStateData = AnimationStateData;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var spine;
|
var spine;
|
||||||
(function (spine) {
|
|
||||||
var AssetManager = (function () {
|
|
||||||
function AssetManager(textureLoader) {
|
|
||||||
this._assets = {};
|
|
||||||
this._errors = {};
|
|
||||||
this._toLoad = 0;
|
|
||||||
this._loaded = 0;
|
|
||||||
this._textureLoader = textureLoader;
|
|
||||||
}
|
|
||||||
AssetManager.prototype.loadText = function (path, success, error) {
|
|
||||||
var _this = this;
|
|
||||||
if (success === void 0) { success = null; }
|
|
||||||
if (error === void 0) { error = null; }
|
|
||||||
this._toLoad++;
|
|
||||||
var request = new XMLHttpRequest();
|
|
||||||
request.onreadystatechange = function () {
|
|
||||||
if (request.readyState == XMLHttpRequest.DONE) {
|
|
||||||
if (request.status >= 200 && request.status < 300) {
|
|
||||||
if (success)
|
|
||||||
success(path, request.responseText);
|
|
||||||
_this._assets[path] = request.responseText;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (error)
|
|
||||||
error(path, "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText);
|
|
||||||
_this._errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
|
|
||||||
}
|
|
||||||
_this._toLoad--;
|
|
||||||
_this._loaded++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
request.open("GET", path, true);
|
|
||||||
request.send();
|
|
||||||
};
|
|
||||||
AssetManager.prototype.loadTexture = function (path, success, error) {
|
|
||||||
var _this = this;
|
|
||||||
if (success === void 0) { success = null; }
|
|
||||||
if (error === void 0) { error = null; }
|
|
||||||
this._toLoad++;
|
|
||||||
var img = new Image();
|
|
||||||
img.src = path;
|
|
||||||
img.onload = function (ev) {
|
|
||||||
if (success)
|
|
||||||
success(path, img);
|
|
||||||
var texture = _this._textureLoader(img);
|
|
||||||
_this._assets[path] = texture;
|
|
||||||
_this._toLoad--;
|
|
||||||
_this._loaded++;
|
|
||||||
};
|
|
||||||
img.onerror = function (ev) {
|
|
||||||
if (error)
|
|
||||||
error(path, "Couldn't load image " + path);
|
|
||||||
_this._errors[path] = "Couldn't load image " + path;
|
|
||||||
_this._toLoad--;
|
|
||||||
_this._loaded++;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
AssetManager.prototype.get = function (path) {
|
|
||||||
return this._assets[path];
|
|
||||||
};
|
|
||||||
AssetManager.prototype.remove = function (path) {
|
|
||||||
var asset = this._assets[path];
|
|
||||||
if (asset.dispose)
|
|
||||||
asset.dispose();
|
|
||||||
this._assets[path] = null;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.removeAll = function () {
|
|
||||||
for (var key in this._assets) {
|
|
||||||
var asset = this._assets[key];
|
|
||||||
if (asset.dispose)
|
|
||||||
asset.dispose();
|
|
||||||
}
|
|
||||||
this._assets = {};
|
|
||||||
};
|
|
||||||
AssetManager.prototype.isLoadingComplete = function () {
|
|
||||||
return this._toLoad == 0;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.toLoad = function () {
|
|
||||||
return this._toLoad;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.loaded = function () {
|
|
||||||
return this._loaded;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.dispose = function () {
|
|
||||||
this.removeAll();
|
|
||||||
};
|
|
||||||
AssetManager.prototype.hasErrors = function () {
|
|
||||||
return Object.keys(this._errors).length > 0;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.errors = function () {
|
|
||||||
return this._errors;
|
|
||||||
};
|
|
||||||
return AssetManager;
|
|
||||||
}());
|
|
||||||
spine.AssetManager = AssetManager;
|
|
||||||
})(spine || (spine = {}));
|
|
||||||
var spine;
|
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
(function (BlendMode) {
|
(function (BlendMode) {
|
||||||
BlendMode[BlendMode["Normal"] = 0] = "Normal";
|
BlendMode[BlendMode["Normal"] = 0] = "Normal";
|
||||||
@ -4516,6 +4530,20 @@ var spine;
|
|||||||
spine.RegionAttachment = RegionAttachment;
|
spine.RegionAttachment = RegionAttachment;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var spine;
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var webgl;
|
||||||
|
(function (webgl) {
|
||||||
|
var AssetManager = (function (_super) {
|
||||||
|
__extends(AssetManager, _super);
|
||||||
|
function AssetManager(gl) {
|
||||||
|
_super.call(this, function (image) { return new spine.webgl.GLTexture(gl, image); });
|
||||||
|
}
|
||||||
|
return AssetManager;
|
||||||
|
}(spine.AssetManager));
|
||||||
|
webgl.AssetManager = AssetManager;
|
||||||
|
})(webgl = spine.webgl || (spine.webgl = {}));
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var webgl;
|
var webgl;
|
||||||
(function (webgl) {
|
(function (webgl) {
|
||||||
@ -5408,9 +5436,7 @@ var spine;
|
|||||||
this._batcher = new spine.webgl.PolygonBatcher(gl);
|
this._batcher = new spine.webgl.PolygonBatcher(gl);
|
||||||
this._mvp.ortho2d(0, 0, 639, 479);
|
this._mvp.ortho2d(0, 0, 639, 479);
|
||||||
this._skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
this._skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
||||||
var assets = this._assetManager = new spine.AssetManager(function (image) {
|
var assets = this._assetManager = new spine.webgl.AssetManager(gl);
|
||||||
return new spine.webgl.GLTexture(gl, image);
|
|
||||||
});
|
|
||||||
assets.loadText(config.atlas);
|
assets.loadText(config.atlas);
|
||||||
assets.loadText(config.json);
|
assets.loadText(config.json);
|
||||||
assets.loadTexture(config.atlas.replace(".atlas", ".png"));
|
assets.loadTexture(config.atlas.replace(".atlas", ".png"));
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
51
spine-ts/build/spine-core.d.ts
vendored
51
spine-ts/build/spine-core.d.ts
vendored
@ -1,3 +1,29 @@
|
|||||||
|
declare module spine {
|
||||||
|
class AssetManager implements Disposable {
|
||||||
|
private _textureLoader;
|
||||||
|
private _assets;
|
||||||
|
private _errors;
|
||||||
|
private _toLoad;
|
||||||
|
private _loaded;
|
||||||
|
constructor(textureLoader: (image: HTMLImageElement) => any);
|
||||||
|
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
|
||||||
|
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
|
||||||
|
get(path: string): any;
|
||||||
|
remove(path: string): void;
|
||||||
|
removeAll(): void;
|
||||||
|
isLoadingComplete(): boolean;
|
||||||
|
toLoad(): number;
|
||||||
|
loaded(): number;
|
||||||
|
dispose(): void;
|
||||||
|
hasErrors(): boolean;
|
||||||
|
errors(): Map<string>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module spine.canvas {
|
||||||
|
class AssetManager extends spine.AssetManager {
|
||||||
|
constructor();
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module spine {
|
declare module spine {
|
||||||
abstract class Texture {
|
abstract class Texture {
|
||||||
protected _image: HTMLImageElement;
|
protected _image: HTMLImageElement;
|
||||||
@ -50,8 +76,8 @@ declare module spine.canvas {
|
|||||||
class SkeletonRenderer {
|
class SkeletonRenderer {
|
||||||
static QUAD_TRIANGLES: number[];
|
static QUAD_TRIANGLES: number[];
|
||||||
private _ctx;
|
private _ctx;
|
||||||
useTriangleRendering: boolean;
|
triangleRendering: boolean;
|
||||||
useDebugRendering: boolean;
|
debugRendering: boolean;
|
||||||
constructor(context: CanvasRenderingContext2D);
|
constructor(context: CanvasRenderingContext2D);
|
||||||
draw(skeleton: Skeleton): void;
|
draw(skeleton: Skeleton): void;
|
||||||
private drawImages(skeleton);
|
private drawImages(skeleton);
|
||||||
@ -295,27 +321,6 @@ declare module spine {
|
|||||||
getMix(from: Animation, to: Animation): number;
|
getMix(from: Animation, to: Animation): number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module spine {
|
|
||||||
class AssetManager implements Disposable {
|
|
||||||
private _textureLoader;
|
|
||||||
private _assets;
|
|
||||||
private _errors;
|
|
||||||
private _toLoad;
|
|
||||||
private _loaded;
|
|
||||||
constructor(textureLoader: (image: HTMLImageElement) => any);
|
|
||||||
loadText(path: string, success?: (path: string, text: string) => void, error?: (path: string, error: string) => void): void;
|
|
||||||
loadTexture(path: string, success?: (path: string, image: HTMLImageElement) => void, error?: (path: string, error: string) => void): void;
|
|
||||||
get(path: string): any;
|
|
||||||
remove(path: string): void;
|
|
||||||
removeAll(): void;
|
|
||||||
isLoadingComplete(): boolean;
|
|
||||||
toLoad(): number;
|
|
||||||
loaded(): number;
|
|
||||||
dispose(): void;
|
|
||||||
hasErrors(): boolean;
|
|
||||||
errors(): Map<string>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module spine {
|
declare module spine {
|
||||||
enum BlendMode {
|
enum BlendMode {
|
||||||
Normal = 0,
|
Normal = 0,
|
||||||
|
|||||||
@ -1,4 +1,120 @@
|
|||||||
var spine;
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var AssetManager = (function () {
|
||||||
|
function AssetManager(textureLoader) {
|
||||||
|
this._assets = {};
|
||||||
|
this._errors = {};
|
||||||
|
this._toLoad = 0;
|
||||||
|
this._loaded = 0;
|
||||||
|
this._textureLoader = textureLoader;
|
||||||
|
}
|
||||||
|
AssetManager.prototype.loadText = function (path, success, error) {
|
||||||
|
var _this = this;
|
||||||
|
if (success === void 0) { success = null; }
|
||||||
|
if (error === void 0) { error = null; }
|
||||||
|
this._toLoad++;
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
request.onreadystatechange = function () {
|
||||||
|
if (request.readyState == XMLHttpRequest.DONE) {
|
||||||
|
if (request.status >= 200 && request.status < 300) {
|
||||||
|
if (success)
|
||||||
|
success(path, request.responseText);
|
||||||
|
_this._assets[path] = request.responseText;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (error)
|
||||||
|
error(path, "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText);
|
||||||
|
_this._errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
|
||||||
|
}
|
||||||
|
_this._toLoad--;
|
||||||
|
_this._loaded++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
request.open("GET", path, true);
|
||||||
|
request.send();
|
||||||
|
};
|
||||||
|
AssetManager.prototype.loadTexture = function (path, success, error) {
|
||||||
|
var _this = this;
|
||||||
|
if (success === void 0) { success = null; }
|
||||||
|
if (error === void 0) { error = null; }
|
||||||
|
this._toLoad++;
|
||||||
|
var img = new Image();
|
||||||
|
img.src = path;
|
||||||
|
img.onload = function (ev) {
|
||||||
|
if (success)
|
||||||
|
success(path, img);
|
||||||
|
var texture = _this._textureLoader(img);
|
||||||
|
_this._assets[path] = texture;
|
||||||
|
_this._toLoad--;
|
||||||
|
_this._loaded++;
|
||||||
|
};
|
||||||
|
img.onerror = function (ev) {
|
||||||
|
if (error)
|
||||||
|
error(path, "Couldn't load image " + path);
|
||||||
|
_this._errors[path] = "Couldn't load image " + path;
|
||||||
|
_this._toLoad--;
|
||||||
|
_this._loaded++;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
AssetManager.prototype.get = function (path) {
|
||||||
|
return this._assets[path];
|
||||||
|
};
|
||||||
|
AssetManager.prototype.remove = function (path) {
|
||||||
|
var asset = this._assets[path];
|
||||||
|
if (asset.dispose)
|
||||||
|
asset.dispose();
|
||||||
|
this._assets[path] = null;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.removeAll = function () {
|
||||||
|
for (var key in this._assets) {
|
||||||
|
var asset = this._assets[key];
|
||||||
|
if (asset.dispose)
|
||||||
|
asset.dispose();
|
||||||
|
}
|
||||||
|
this._assets = {};
|
||||||
|
};
|
||||||
|
AssetManager.prototype.isLoadingComplete = function () {
|
||||||
|
return this._toLoad == 0;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.toLoad = function () {
|
||||||
|
return this._toLoad;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.loaded = function () {
|
||||||
|
return this._loaded;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.dispose = function () {
|
||||||
|
this.removeAll();
|
||||||
|
};
|
||||||
|
AssetManager.prototype.hasErrors = function () {
|
||||||
|
return Object.keys(this._errors).length > 0;
|
||||||
|
};
|
||||||
|
AssetManager.prototype.errors = function () {
|
||||||
|
return this._errors;
|
||||||
|
};
|
||||||
|
return AssetManager;
|
||||||
|
}());
|
||||||
|
spine.AssetManager = AssetManager;
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var __extends = (this && this.__extends) || function (d, b) {
|
||||||
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||||
|
function __() { this.constructor = d; }
|
||||||
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
|
};
|
||||||
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var canvas;
|
||||||
|
(function (canvas) {
|
||||||
|
var AssetManager = (function (_super) {
|
||||||
|
__extends(AssetManager, _super);
|
||||||
|
function AssetManager() {
|
||||||
|
_super.call(this, function (image) { return new spine.canvas.CanvasTexture(image); });
|
||||||
|
}
|
||||||
|
return AssetManager;
|
||||||
|
}(spine.AssetManager));
|
||||||
|
canvas.AssetManager = AssetManager;
|
||||||
|
})(canvas = spine.canvas || (spine.canvas = {}));
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var Texture = (function () {
|
var Texture = (function () {
|
||||||
function Texture(image) {
|
function Texture(image) {
|
||||||
@ -64,11 +180,6 @@ var spine;
|
|||||||
}());
|
}());
|
||||||
spine.TextureRegion = TextureRegion;
|
spine.TextureRegion = TextureRegion;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var __extends = (this && this.__extends) || function (d, b) {
|
|
||||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
||||||
function __() { this.constructor = d; }
|
|
||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
||||||
};
|
|
||||||
var spine;
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var canvas;
|
var canvas;
|
||||||
@ -92,12 +203,12 @@ var spine;
|
|||||||
(function (canvas) {
|
(function (canvas) {
|
||||||
var SkeletonRenderer = (function () {
|
var SkeletonRenderer = (function () {
|
||||||
function SkeletonRenderer(context) {
|
function SkeletonRenderer(context) {
|
||||||
this.useTriangleRendering = false;
|
this.triangleRendering = false;
|
||||||
this.useDebugRendering = false;
|
this.debugRendering = false;
|
||||||
this._ctx = context;
|
this._ctx = context;
|
||||||
}
|
}
|
||||||
SkeletonRenderer.prototype.draw = function (skeleton) {
|
SkeletonRenderer.prototype.draw = function (skeleton) {
|
||||||
if (this.useTriangleRendering)
|
if (this.triangleRendering)
|
||||||
this.drawTriangles(skeleton);
|
this.drawTriangles(skeleton);
|
||||||
else
|
else
|
||||||
this.drawImages(skeleton);
|
this.drawImages(skeleton);
|
||||||
@ -105,7 +216,7 @@ var spine;
|
|||||||
SkeletonRenderer.prototype.drawImages = function (skeleton) {
|
SkeletonRenderer.prototype.drawImages = function (skeleton) {
|
||||||
var ctx = this._ctx;
|
var ctx = this._ctx;
|
||||||
var drawOrder = skeleton.drawOrder;
|
var drawOrder = skeleton.drawOrder;
|
||||||
if (this.useDebugRendering)
|
if (this.debugRendering)
|
||||||
ctx.strokeStyle = "green";
|
ctx.strokeStyle = "green";
|
||||||
for (var i = 0, n = drawOrder.length; i < n; i++) {
|
for (var i = 0, n = drawOrder.length; i < n; i++) {
|
||||||
var slot = drawOrder[i];
|
var slot = drawOrder[i];
|
||||||
@ -141,7 +252,7 @@ var spine;
|
|||||||
else {
|
else {
|
||||||
ctx.drawImage(image, region.x, region.y, region.width, region.height, 0, 0, w, h);
|
ctx.drawImage(image, region.x, region.y, region.width, region.height, 0, 0, w, h);
|
||||||
}
|
}
|
||||||
if (this.useDebugRendering)
|
if (this.debugRendering)
|
||||||
ctx.strokeRect(0, 0, w, h);
|
ctx.strokeRect(0, 0, w, h);
|
||||||
ctx.rotate(-rotation);
|
ctx.rotate(-rotation);
|
||||||
ctx.translate(-x, -y);
|
ctx.translate(-x, -y);
|
||||||
@ -184,7 +295,7 @@ var spine;
|
|||||||
var x1 = vertices[t2], y1 = vertices[t2 + 1], u1 = vertices[t2 + 6], v1 = vertices[t2 + 7];
|
var x1 = vertices[t2], y1 = vertices[t2 + 1], u1 = vertices[t2 + 6], v1 = vertices[t2 + 7];
|
||||||
var x2 = vertices[t3], y2 = vertices[t3 + 1], u2 = vertices[t3 + 6], v2 = vertices[t3 + 7];
|
var x2 = vertices[t3], y2 = vertices[t3 + 1], u2 = vertices[t3 + 6], v2 = vertices[t3 + 7];
|
||||||
this.drawTriangle(texture, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
|
this.drawTriangle(texture, x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2);
|
||||||
if (this.useDebugRendering) {
|
if (this.debugRendering) {
|
||||||
ctx.strokeStyle = "green";
|
ctx.strokeStyle = "green";
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(x0, y0);
|
ctx.moveTo(x0, y0);
|
||||||
@ -1215,103 +1326,6 @@ var spine;
|
|||||||
spine.AnimationStateData = AnimationStateData;
|
spine.AnimationStateData = AnimationStateData;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var spine;
|
var spine;
|
||||||
(function (spine) {
|
|
||||||
var AssetManager = (function () {
|
|
||||||
function AssetManager(textureLoader) {
|
|
||||||
this._assets = {};
|
|
||||||
this._errors = {};
|
|
||||||
this._toLoad = 0;
|
|
||||||
this._loaded = 0;
|
|
||||||
this._textureLoader = textureLoader;
|
|
||||||
}
|
|
||||||
AssetManager.prototype.loadText = function (path, success, error) {
|
|
||||||
var _this = this;
|
|
||||||
if (success === void 0) { success = null; }
|
|
||||||
if (error === void 0) { error = null; }
|
|
||||||
this._toLoad++;
|
|
||||||
var request = new XMLHttpRequest();
|
|
||||||
request.onreadystatechange = function () {
|
|
||||||
if (request.readyState == XMLHttpRequest.DONE) {
|
|
||||||
if (request.status >= 200 && request.status < 300) {
|
|
||||||
if (success)
|
|
||||||
success(path, request.responseText);
|
|
||||||
_this._assets[path] = request.responseText;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (error)
|
|
||||||
error(path, "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText);
|
|
||||||
_this._errors[path] = "Couldn't load text " + path + ": status " + request.status + ", " + request.responseText;
|
|
||||||
}
|
|
||||||
_this._toLoad--;
|
|
||||||
_this._loaded++;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
request.open("GET", path, true);
|
|
||||||
request.send();
|
|
||||||
};
|
|
||||||
AssetManager.prototype.loadTexture = function (path, success, error) {
|
|
||||||
var _this = this;
|
|
||||||
if (success === void 0) { success = null; }
|
|
||||||
if (error === void 0) { error = null; }
|
|
||||||
this._toLoad++;
|
|
||||||
var img = new Image();
|
|
||||||
img.src = path;
|
|
||||||
img.onload = function (ev) {
|
|
||||||
if (success)
|
|
||||||
success(path, img);
|
|
||||||
var texture = _this._textureLoader(img);
|
|
||||||
_this._assets[path] = texture;
|
|
||||||
_this._toLoad--;
|
|
||||||
_this._loaded++;
|
|
||||||
};
|
|
||||||
img.onerror = function (ev) {
|
|
||||||
if (error)
|
|
||||||
error(path, "Couldn't load image " + path);
|
|
||||||
_this._errors[path] = "Couldn't load image " + path;
|
|
||||||
_this._toLoad--;
|
|
||||||
_this._loaded++;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
AssetManager.prototype.get = function (path) {
|
|
||||||
return this._assets[path];
|
|
||||||
};
|
|
||||||
AssetManager.prototype.remove = function (path) {
|
|
||||||
var asset = this._assets[path];
|
|
||||||
if (asset.dispose)
|
|
||||||
asset.dispose();
|
|
||||||
this._assets[path] = null;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.removeAll = function () {
|
|
||||||
for (var key in this._assets) {
|
|
||||||
var asset = this._assets[key];
|
|
||||||
if (asset.dispose)
|
|
||||||
asset.dispose();
|
|
||||||
}
|
|
||||||
this._assets = {};
|
|
||||||
};
|
|
||||||
AssetManager.prototype.isLoadingComplete = function () {
|
|
||||||
return this._toLoad == 0;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.toLoad = function () {
|
|
||||||
return this._toLoad;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.loaded = function () {
|
|
||||||
return this._loaded;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.dispose = function () {
|
|
||||||
this.removeAll();
|
|
||||||
};
|
|
||||||
AssetManager.prototype.hasErrors = function () {
|
|
||||||
return Object.keys(this._errors).length > 0;
|
|
||||||
};
|
|
||||||
AssetManager.prototype.errors = function () {
|
|
||||||
return this._errors;
|
|
||||||
};
|
|
||||||
return AssetManager;
|
|
||||||
}());
|
|
||||||
spine.AssetManager = AssetManager;
|
|
||||||
})(spine || (spine = {}));
|
|
||||||
var spine;
|
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
(function (BlendMode) {
|
(function (BlendMode) {
|
||||||
BlendMode[BlendMode["Normal"] = 0] = "Normal";
|
BlendMode[BlendMode["Normal"] = 0] = "Normal";
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
5
spine-ts/build/spine-webgl.d.ts
vendored
5
spine-ts/build/spine-webgl.d.ts
vendored
@ -873,6 +873,11 @@ declare module spine {
|
|||||||
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
|
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module spine.webgl {
|
||||||
|
class AssetManager extends spine.AssetManager {
|
||||||
|
constructor(gl: WebGLRenderingContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module spine.webgl {
|
declare module spine.webgl {
|
||||||
class GLTexture extends Texture implements Disposable {
|
class GLTexture extends Texture implements Disposable {
|
||||||
private _gl;
|
private _gl;
|
||||||
|
|||||||
@ -4354,6 +4354,20 @@ var spine;
|
|||||||
spine.RegionAttachment = RegionAttachment;
|
spine.RegionAttachment = RegionAttachment;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var spine;
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var webgl;
|
||||||
|
(function (webgl) {
|
||||||
|
var AssetManager = (function (_super) {
|
||||||
|
__extends(AssetManager, _super);
|
||||||
|
function AssetManager(gl) {
|
||||||
|
_super.call(this, function (image) { return new spine.webgl.GLTexture(gl, image); });
|
||||||
|
}
|
||||||
|
return AssetManager;
|
||||||
|
}(spine.AssetManager));
|
||||||
|
webgl.AssetManager = AssetManager;
|
||||||
|
})(webgl = spine.webgl || (spine.webgl = {}));
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var webgl;
|
var webgl;
|
||||||
(function (webgl) {
|
(function (webgl) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
5
spine-ts/build/spine-widget.d.ts
vendored
5
spine-ts/build/spine-widget.d.ts
vendored
@ -873,6 +873,11 @@ declare module spine {
|
|||||||
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
|
updateWorldVertices(slot: Slot, premultipliedAlpha: boolean): ArrayLike<number>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module spine.webgl {
|
||||||
|
class AssetManager extends spine.AssetManager {
|
||||||
|
constructor(gl: WebGLRenderingContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module spine.webgl {
|
declare module spine.webgl {
|
||||||
class GLTexture extends Texture implements Disposable {
|
class GLTexture extends Texture implements Disposable {
|
||||||
private _gl;
|
private _gl;
|
||||||
|
|||||||
@ -4354,6 +4354,20 @@ var spine;
|
|||||||
spine.RegionAttachment = RegionAttachment;
|
spine.RegionAttachment = RegionAttachment;
|
||||||
})(spine || (spine = {}));
|
})(spine || (spine = {}));
|
||||||
var spine;
|
var spine;
|
||||||
|
(function (spine) {
|
||||||
|
var webgl;
|
||||||
|
(function (webgl) {
|
||||||
|
var AssetManager = (function (_super) {
|
||||||
|
__extends(AssetManager, _super);
|
||||||
|
function AssetManager(gl) {
|
||||||
|
_super.call(this, function (image) { return new spine.webgl.GLTexture(gl, image); });
|
||||||
|
}
|
||||||
|
return AssetManager;
|
||||||
|
}(spine.AssetManager));
|
||||||
|
webgl.AssetManager = AssetManager;
|
||||||
|
})(webgl = spine.webgl || (spine.webgl = {}));
|
||||||
|
})(spine || (spine = {}));
|
||||||
|
var spine;
|
||||||
(function (spine) {
|
(function (spine) {
|
||||||
var webgl;
|
var webgl;
|
||||||
(function (webgl) {
|
(function (webgl) {
|
||||||
@ -5246,9 +5260,7 @@ var spine;
|
|||||||
this._batcher = new spine.webgl.PolygonBatcher(gl);
|
this._batcher = new spine.webgl.PolygonBatcher(gl);
|
||||||
this._mvp.ortho2d(0, 0, 639, 479);
|
this._mvp.ortho2d(0, 0, 639, 479);
|
||||||
this._skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
this._skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
||||||
var assets = this._assetManager = new spine.AssetManager(function (image) {
|
var assets = this._assetManager = new spine.webgl.AssetManager(gl);
|
||||||
return new spine.webgl.GLTexture(gl, image);
|
|
||||||
});
|
|
||||||
assets.loadText(config.atlas);
|
assets.loadText(config.atlas);
|
||||||
assets.loadText(config.json);
|
assets.loadText(config.json);
|
||||||
assets.loadTexture(config.atlas.replace(".atlas", ".png"));
|
assets.loadTexture(config.atlas.replace(".atlas", ".png"));
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -24,13 +24,11 @@ function init () {
|
|||||||
|
|
||||||
skeletonRenderer = new spine.canvas.SkeletonRenderer(context);
|
skeletonRenderer = new spine.canvas.SkeletonRenderer(context);
|
||||||
// enable debug rendering
|
// enable debug rendering
|
||||||
skeletonRenderer.useDebugRendering = true;
|
skeletonRenderer.debugRendering = true;
|
||||||
// enable the triangle renderer, supports meshes, but may produce artifacts in some browsers
|
// enable the triangle renderer, supports meshes, but may produce artifacts in some browsers
|
||||||
skeletonRenderer.useTriangleRendering = true;
|
skeletonRenderer.triangleRendering = true;
|
||||||
|
|
||||||
assetManager = new spine.AssetManager(function(image) {
|
assetManager = new spine.canvas.AssetManager();
|
||||||
return new spine.canvas.CanvasTexture(image);
|
|
||||||
});
|
|
||||||
|
|
||||||
assetManager.loadText("assets/spineboy.json");
|
assetManager.loadText("assets/spineboy.json");
|
||||||
assetManager.loadText("assets/spineboy.atlas");
|
assetManager.loadText("assets/spineboy.atlas");
|
||||||
|
|||||||
40
spine-ts/canvas/src/AssetManager.ts
Normal file
40
spine-ts/canvas/src/AssetManager.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes Software License
|
||||||
|
* Version 2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
/// <reference path="../../core/src/AssetManager.ts"/>
|
||||||
|
|
||||||
|
module spine.canvas {
|
||||||
|
export class AssetManager extends spine.AssetManager {
|
||||||
|
constructor () {
|
||||||
|
super((image: HTMLImageElement) => { return new spine.canvas.CanvasTexture(image); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -36,9 +36,7 @@ function init () {
|
|||||||
batcher = new spine.webgl.PolygonBatcher(gl);
|
batcher = new spine.webgl.PolygonBatcher(gl);
|
||||||
mvp.ortho2d(0, 0, 639, 479);
|
mvp.ortho2d(0, 0, 639, 479);
|
||||||
skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
||||||
assetManager = new spine.AssetManager(function(image) {
|
assetManager = new spine.webgl.AssetManager(gl);
|
||||||
return new spine.webgl.GLTexture(gl, image);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Tell AssetManager to load the resources for each model, including the exported .json file, the .atlas file and the .png
|
// Tell AssetManager to load the resources for each model, including the exported .json file, the .atlas file and the .png
|
||||||
// file for the atlas. We then wait until all resources are loaded in the load() method.
|
// file for the atlas. We then wait until all resources are loaded in the load() method.
|
||||||
|
|||||||
38
spine-ts/webgl/src/AssetManager.ts
Normal file
38
spine-ts/webgl/src/AssetManager.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Spine Runtimes Software License
|
||||||
|
* Version 2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
module spine.webgl {
|
||||||
|
export class AssetManager extends spine.AssetManager {
|
||||||
|
constructor (gl: WebGLRenderingContext) {
|
||||||
|
super((image: HTMLImageElement) => { return new spine.webgl.GLTexture(gl, image); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -37,7 +37,7 @@ module spine {
|
|||||||
canvas: HTMLCanvasElement;
|
canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
private _config: SpineWidgetConfig;
|
private _config: SpineWidgetConfig;
|
||||||
private _assetManager: spine.AssetManager;
|
private _assetManager: spine.webgl.AssetManager;
|
||||||
private _shader: spine.webgl.Shader;
|
private _shader: spine.webgl.Shader;
|
||||||
private _batcher: spine.webgl.PolygonBatcher;
|
private _batcher: spine.webgl.PolygonBatcher;
|
||||||
private _mvp = new spine.webgl.Matrix4();
|
private _mvp = new spine.webgl.Matrix4();
|
||||||
@ -69,9 +69,7 @@ module spine {
|
|||||||
this._mvp.ortho2d(0, 0, 639, 479);
|
this._mvp.ortho2d(0, 0, 639, 479);
|
||||||
this._skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
this._skeletonRenderer = new spine.webgl.SkeletonRenderer(gl);
|
||||||
|
|
||||||
let assets = this._assetManager = new spine.AssetManager((image: HTMLImageElement) => {
|
let assets = this._assetManager = new spine.webgl.AssetManager(gl);
|
||||||
return new spine.webgl.GLTexture(gl, image);
|
|
||||||
});
|
|
||||||
assets.loadText(config.atlas);
|
assets.loadText(config.atlas);
|
||||||
assets.loadText(config.json);
|
assets.loadText(config.json);
|
||||||
assets.loadTexture(config.atlas.replace(".atlas", ".png"));
|
assets.loadTexture(config.atlas.replace(".atlas", ".png"));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user