mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[ts][player] Add interactive option to allow click/touch interaction. Closes #2852.
This commit is contained in:
parent
e24b1a25d8
commit
fd20a0c009
@ -148,6 +148,9 @@ export interface SpinePlayerConfig {
|
||||
filter settings from the texture atlas are used. Default: true */
|
||||
mipmaps?: boolean
|
||||
|
||||
/* Optional: Whether the player responds to user click/touch (play/pause, or control bones). Default: true */
|
||||
interactive?: boolean
|
||||
|
||||
/* Optional: List of bone names that the user can drag to position. Default: none */
|
||||
controlBones?: string[]
|
||||
|
||||
@ -306,6 +309,7 @@ export class SpinePlayer implements Disposable {
|
||||
if (config.premultipliedAlpha === void 0) config.premultipliedAlpha = true;
|
||||
if (config.preserveDrawingBuffer === void 0) config.preserveDrawingBuffer = false;
|
||||
if (config.mipmaps === void 0) config.mipmaps = true;
|
||||
if (config.interactive === void 0) config.interactive = true;
|
||||
if (!config.debug) config.debug = {
|
||||
bones: false,
|
||||
clipping: false,
|
||||
@ -586,6 +590,7 @@ export class SpinePlayer implements Disposable {
|
||||
let skeleton = this.skeleton!;
|
||||
let renderer = this.sceneRenderer!;
|
||||
|
||||
if (config.interactive) {
|
||||
let closest = function (x: number, y: number): Bone | null {
|
||||
mouse.set(x, canvas.clientHeight - y, 0)
|
||||
offset.x = offset.y = 0;
|
||||
@ -637,6 +642,8 @@ export class SpinePlayer implements Disposable {
|
||||
},
|
||||
moved: (x, y) => closest(x, y)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (config.showControls) {
|
||||
// For manual hover to work, we need to disable hidding controls if the mouse/touch entered the clickable area of a child of the controls.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user