mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +08:00
[ts][player] Added scale parameter to config.
This commit is contained in:
parent
fb8f931fbf
commit
d8b9028210
@ -40,6 +40,9 @@ export interface SpinePlayerConfig {
|
|||||||
/* The URL of the skeleton binary file (.skel). Undefined if jsonUrl is given. */
|
/* The URL of the skeleton binary file (.skel). Undefined if jsonUrl is given. */
|
||||||
binaryUrl?: string
|
binaryUrl?: string
|
||||||
|
|
||||||
|
/* The scale when loading the skeleton data. Default: 1 */
|
||||||
|
scale?: number
|
||||||
|
|
||||||
/* The URL of the skeleton atlas file (.atlas). Atlas page images are automatically resolved. */
|
/* The URL of the skeleton atlas file (.atlas). Atlas page images are automatically resolved. */
|
||||||
atlasUrl?: string
|
atlasUrl?: string
|
||||||
|
|
||||||
@ -284,6 +287,7 @@ export class SpinePlayer implements Disposable {
|
|||||||
if (!config) throw new Error("A configuration object must be passed to to new SpinePlayer().");
|
if (!config) throw new Error("A configuration object must be passed to to new SpinePlayer().");
|
||||||
if ((config as any).skelUrl) config.binaryUrl = (config as any).skelUrl;
|
if ((config as any).skelUrl) config.binaryUrl = (config as any).skelUrl;
|
||||||
if (!config.jsonUrl && !config.binaryUrl) throw new Error("A URL must be specified for the skeleton JSON or binary file.");
|
if (!config.jsonUrl && !config.binaryUrl) throw new Error("A URL must be specified for the skeleton JSON or binary file.");
|
||||||
|
if (!config.scale) config.scale = 1;
|
||||||
if (!config.atlasUrl) throw new Error("A URL must be specified for the atlas file.");
|
if (!config.atlasUrl) throw new Error("A URL must be specified for the atlas file.");
|
||||||
if (!config.backgroundColor) config.backgroundColor = config.alpha ? "00000000" : "000000";
|
if (!config.backgroundColor) config.backgroundColor = config.alpha ? "00000000" : "000000";
|
||||||
if (!config.fullScreenBackgroundColor) config.fullScreenBackgroundColor = config.backgroundColor;
|
if (!config.fullScreenBackgroundColor) config.fullScreenBackgroundColor = config.backgroundColor;
|
||||||
@ -460,29 +464,25 @@ export class SpinePlayer implements Disposable {
|
|||||||
|
|
||||||
// Load skeleton data.
|
// Load skeleton data.
|
||||||
let skeletonData: SkeletonData;
|
let skeletonData: SkeletonData;
|
||||||
if (config.jsonUrl) {
|
try {
|
||||||
try {
|
let loader: any, data: any, attachmentLoader = new AtlasAttachmentLoader(atlas);
|
||||||
let jsonData = this.assetManager!.remove(config.jsonUrl);
|
if (config.jsonUrl) {
|
||||||
if (!jsonData) throw new Error("Empty JSON data.");
|
data = this.assetManager!.remove(config.jsonUrl);
|
||||||
|
if (!data) throw new Error("Empty JSON data.");
|
||||||
if (config.jsonField) {
|
if (config.jsonField) {
|
||||||
jsonData = jsonData[config.jsonField];
|
data = data[config.jsonField];
|
||||||
if (!jsonData) throw new Error("JSON field does not exist: " + config.jsonField);
|
if (!data) throw new Error("JSON field does not exist: " + config.jsonField);
|
||||||
}
|
}
|
||||||
let json = new SkeletonJson(new AtlasAttachmentLoader(atlas));
|
loader = new SkeletonJson(attachmentLoader);
|
||||||
skeletonData = json.readSkeletonData(jsonData);
|
} else {
|
||||||
} catch (e) {
|
data = this.assetManager!.remove(config.binaryUrl!);
|
||||||
this.showError(`Error: Could not load skeleton JSON.\n${(e as any).message}`, e as any);
|
loader = new SkeletonBinary(attachmentLoader);
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let binaryData = this.assetManager!.remove(config.binaryUrl!);
|
|
||||||
let binary = new SkeletonBinary(new AtlasAttachmentLoader(atlas));
|
|
||||||
try {
|
|
||||||
skeletonData = binary.readSkeletonData(binaryData);
|
|
||||||
} catch (e) {
|
|
||||||
this.showError(`Error: Could not load skeleton binary.\n${(e as any).message}`, e as any);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
loader.scale = config.scale;
|
||||||
|
skeletonData = loader.readSkeletonData(data);
|
||||||
|
} catch (e) {
|
||||||
|
this.showError(`Error: Could not load skeleton data.\n${(e as any).message}`, e as any);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
this.skeleton = new Skeleton(skeletonData);
|
this.skeleton = new Skeleton(skeletonData);
|
||||||
let stateData = new AnimationStateData(skeletonData);
|
let stateData = new AnimationStateData(skeletonData);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user