mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts][player] Added viewport transitions between animation changes. Configurable via config.viewport.transitionTime.
This commit is contained in:
parent
f6eb468d32
commit
05d5f6d6e0
2
spine-ts/build/spine-widget.d.ts
vendored
2
spine-ts/build/spine-widget.d.ts
vendored
@ -1724,6 +1724,7 @@ declare module spine {
|
|||||||
padBottom: string | number;
|
padBottom: string | number;
|
||||||
animations: Map<Viewport>;
|
animations: Map<Viewport>;
|
||||||
debugRender: boolean;
|
debugRender: boolean;
|
||||||
|
transitionTime: number;
|
||||||
};
|
};
|
||||||
alpha: boolean;
|
alpha: boolean;
|
||||||
backgroundColor: string;
|
backgroundColor: string;
|
||||||
@ -1765,6 +1766,7 @@ declare module spine {
|
|||||||
private animationViewports;
|
private animationViewports;
|
||||||
private currentViewport;
|
private currentViewport;
|
||||||
private previousViewport;
|
private previousViewport;
|
||||||
|
private viewportTransitionStart;
|
||||||
private selectedBones;
|
private selectedBones;
|
||||||
constructor(parent: HTMLElement, config: SpinePlayerConfig);
|
constructor(parent: HTMLElement, config: SpinePlayerConfig);
|
||||||
validateConfig(config: SpinePlayerConfig): SpinePlayerConfig;
|
validateConfig(config: SpinePlayerConfig): SpinePlayerConfig;
|
||||||
|
|||||||
@ -9542,6 +9542,7 @@ var spine;
|
|||||||
this.animationViewports = {};
|
this.animationViewports = {};
|
||||||
this.currentViewport = null;
|
this.currentViewport = null;
|
||||||
this.previousViewport = null;
|
this.previousViewport = null;
|
||||||
|
this.viewportTransitionStart = 0;
|
||||||
parent.appendChild(this.render());
|
parent.appendChild(this.render());
|
||||||
}
|
}
|
||||||
SpinePlayer.prototype.validateConfig = function (config) {
|
SpinePlayer.prototype.validateConfig = function (config) {
|
||||||
@ -9860,6 +9861,21 @@ var spine;
|
|||||||
width: this.currentViewport.width + this.currentViewport.padLeft + this.currentViewport.padRight,
|
width: this.currentViewport.width + this.currentViewport.padLeft + this.currentViewport.padRight,
|
||||||
height: this.currentViewport.height + this.currentViewport.padBottom + this.currentViewport.padTop
|
height: this.currentViewport.height + this.currentViewport.padBottom + this.currentViewport.padTop
|
||||||
};
|
};
|
||||||
|
var transitionAlpha = ((performance.now() - this.viewportTransitionStart) / 1000) / this.config.viewport.transitionTime;
|
||||||
|
if (this.previousViewport && transitionAlpha < 1) {
|
||||||
|
var oldViewport = {
|
||||||
|
x: this.previousViewport.x - this.previousViewport.padLeft,
|
||||||
|
y: this.previousViewport.y - this.previousViewport.padBottom,
|
||||||
|
width: this.previousViewport.width + this.previousViewport.padLeft + this.previousViewport.padRight,
|
||||||
|
height: this.previousViewport.height + this.previousViewport.padBottom + this.previousViewport.padTop
|
||||||
|
};
|
||||||
|
viewport = {
|
||||||
|
x: oldViewport.x + (viewport.x - oldViewport.x) * transitionAlpha,
|
||||||
|
y: oldViewport.y + (viewport.y - oldViewport.y) * transitionAlpha,
|
||||||
|
width: oldViewport.width + (viewport.width - oldViewport.width) * transitionAlpha,
|
||||||
|
height: oldViewport.height + (viewport.height - oldViewport.height) * transitionAlpha
|
||||||
|
};
|
||||||
|
}
|
||||||
var viewportSize = this.scale(viewport.width, viewport.height, this.canvas.width, this.canvas.height);
|
var viewportSize = this.scale(viewport.width, viewport.height, this.canvas.width, this.canvas.height);
|
||||||
this.sceneRenderer.camera.zoom = viewport.width / viewportSize.x;
|
this.sceneRenderer.camera.zoom = viewport.width / viewportSize.x;
|
||||||
this.sceneRenderer.camera.position.x = viewport.x + viewport.width / 2;
|
this.sceneRenderer.camera.position.x = viewport.x + viewport.width / 2;
|
||||||
@ -9968,11 +9984,14 @@ var spine;
|
|||||||
if (!this.config.viewport) {
|
if (!this.config.viewport) {
|
||||||
this.config.viewport = {
|
this.config.viewport = {
|
||||||
animations: {},
|
animations: {},
|
||||||
debugRender: false
|
debugRender: false,
|
||||||
|
transitionTime: 0.2
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (typeof this.config.viewport.debugRender === "undefined")
|
if (typeof this.config.viewport.debugRender === "undefined")
|
||||||
this.config.viewport.debugRender = false;
|
this.config.viewport.debugRender = false;
|
||||||
|
if (typeof this.config.viewport.transitionTime === "undefined")
|
||||||
|
this.config.viewport.transitionTime = 0.2;
|
||||||
if (!this.config.viewport.animations) {
|
if (!this.config.viewport.animations) {
|
||||||
this.config.viewport.animations = {};
|
this.config.viewport.animations = {};
|
||||||
}
|
}
|
||||||
@ -10176,6 +10195,7 @@ var spine;
|
|||||||
viewport.padBottom = this.percentageToWorldUnit(viewport.height, viewport.padBottom);
|
viewport.padBottom = this.percentageToWorldUnit(viewport.height, viewport.padBottom);
|
||||||
viewport.padTop = this.percentageToWorldUnit(viewport.height, viewport.padTop);
|
viewport.padTop = this.percentageToWorldUnit(viewport.height, viewport.padTop);
|
||||||
this.currentViewport = viewport;
|
this.currentViewport = viewport;
|
||||||
|
this.viewportTransitionStart = performance.now();
|
||||||
this.animationState.clearTracks();
|
this.animationState.clearTracks();
|
||||||
this.skeleton.setToSetupPose();
|
this.skeleton.setToSetupPose();
|
||||||
this.animationState.setAnimation(0, this.config.animation, true);
|
this.animationState.setAnimation(0, this.config.animation, true);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -24,16 +24,7 @@ body {
|
|||||||
premultipliedAlpha: true,
|
premultipliedAlpha: true,
|
||||||
backgroundColor: "#cccccc",
|
backgroundColor: "#cccccc",
|
||||||
viewport: {
|
viewport: {
|
||||||
padLeft: "10%",
|
|
||||||
padRight: "10%",
|
|
||||||
padTop: "10%",
|
|
||||||
padBottom: "10%",
|
|
||||||
debugRender: true,
|
debugRender: true,
|
||||||
animations: {
|
|
||||||
"jump": {
|
|
||||||
padTop: "-20%"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -91,7 +91,8 @@
|
|||||||
padTop: string | number
|
padTop: string | number
|
||||||
padBottom: string | number
|
padBottom: string | number
|
||||||
animations: Map<Viewport>
|
animations: Map<Viewport>
|
||||||
debugRender: boolean
|
debugRender: boolean,
|
||||||
|
transitionTime: number
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Optional: whether the canvas should be transparent. Default: false. */
|
/* Optional: whether the canvas should be transparent. Default: false. */
|
||||||
@ -303,6 +304,7 @@
|
|||||||
private animationViewports: Map<Viewport> = {}
|
private animationViewports: Map<Viewport> = {}
|
||||||
private currentViewport: Viewport = null;
|
private currentViewport: Viewport = null;
|
||||||
private previousViewport: Viewport = null;
|
private previousViewport: Viewport = null;
|
||||||
|
private viewportTransitionStart = 0;
|
||||||
|
|
||||||
private selectedBones: Bone[];
|
private selectedBones: Bone[];
|
||||||
|
|
||||||
@ -703,6 +705,23 @@
|
|||||||
height: this.currentViewport.height + (this.currentViewport.padBottom as number) + (this.currentViewport.padTop as number)
|
height: this.currentViewport.height + (this.currentViewport.padBottom as number) + (this.currentViewport.padTop as number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let transitionAlpha = ((performance.now() - this.viewportTransitionStart) / 1000) / this.config.viewport.transitionTime;
|
||||||
|
if (this.previousViewport && transitionAlpha < 1) {
|
||||||
|
let oldViewport = {
|
||||||
|
x: this.previousViewport.x - (this.previousViewport.padLeft as number),
|
||||||
|
y: this.previousViewport.y - (this.previousViewport.padBottom as number),
|
||||||
|
width: this.previousViewport.width + (this.previousViewport.padLeft as number) + (this.previousViewport.padRight as number),
|
||||||
|
height: this.previousViewport.height + (this.previousViewport.padBottom as number) + (this.previousViewport.padTop as number)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewport = {
|
||||||
|
x: oldViewport.x + (viewport.x - oldViewport.x) * transitionAlpha,
|
||||||
|
y: oldViewport.y + (viewport.y - oldViewport.y) * transitionAlpha,
|
||||||
|
width: oldViewport.width + (viewport.width - oldViewport.width) * transitionAlpha,
|
||||||
|
height: oldViewport.height + (viewport.height - oldViewport.height) * transitionAlpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let viewportSize = this.scale(viewport.width, viewport.height, this.canvas.width, this.canvas.height);
|
let viewportSize = this.scale(viewport.width, viewport.height, this.canvas.width, this.canvas.height);
|
||||||
|
|
||||||
this.sceneRenderer.camera.zoom = viewport.width / viewportSize.x;
|
this.sceneRenderer.camera.zoom = viewport.width / viewportSize.x;
|
||||||
@ -832,10 +851,12 @@
|
|||||||
if (!this.config.viewport) {
|
if (!this.config.viewport) {
|
||||||
(this.config.viewport as any) = {
|
(this.config.viewport as any) = {
|
||||||
animations: {},
|
animations: {},
|
||||||
debugRender: false
|
debugRender: false,
|
||||||
|
transitionTime: 0.2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof this.config.viewport.debugRender === "undefined") this.config.viewport.debugRender = false;
|
if (typeof this.config.viewport.debugRender === "undefined") this.config.viewport.debugRender = false;
|
||||||
|
if (typeof this.config.viewport.transitionTime === "undefined") this.config.viewport.transitionTime = 0.2;
|
||||||
if (!this.config.viewport.animations) {
|
if (!this.config.viewport.animations) {
|
||||||
this.config.viewport.animations = {};
|
this.config.viewport.animations = {};
|
||||||
} else {
|
} else {
|
||||||
@ -1055,6 +1076,7 @@
|
|||||||
|
|
||||||
// Adjust x, y, width, and height by padding.
|
// Adjust x, y, width, and height by padding.
|
||||||
this.currentViewport = viewport;
|
this.currentViewport = viewport;
|
||||||
|
this.viewportTransitionStart = performance.now();
|
||||||
|
|
||||||
this.animationState.clearTracks();
|
this.animationState.clearTracks();
|
||||||
this.skeleton.setToSetupPose();
|
this.skeleton.setToSetupPose();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user