mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[ts][player] Fixed scrubbing + physics
This commit is contained in:
parent
ec91d52c50
commit
a49de250ed
39
spine-ts/spine-player/example/physics.html
Normal file
39
spine-ts/spine-player/example/physics.html
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<script src="../dist/iife/spine-player.js"></script>
|
||||||
|
<link rel="stylesheet" href="../dist/spine-player.css">
|
||||||
|
</head>
|
||||||
|
<body style="margin:0">
|
||||||
|
<div id="player" style="position: absolute; width: 100%; height: 100vh;">
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
var mouse = new spine.Vector3(),
|
||||||
|
last = new spine.Vector3();
|
||||||
|
new spine.SpinePlayer("player", {
|
||||||
|
skelUrl: "assets/celestial-circus-pro.skel",
|
||||||
|
atlasUrl: "assets/celestial-circus-pma.atlas",
|
||||||
|
showControls: true,
|
||||||
|
animation: "swing",
|
||||||
|
success: (player) => {
|
||||||
|
new spine.Input(player.canvas).addListener({
|
||||||
|
down: (x, y) => {
|
||||||
|
player.sceneRenderer.camera.screenToWorld(mouse.set(x, y, 0), player.canvas.clientWidth, player.canvas.clientHeight);
|
||||||
|
last.setFrom(mouse);
|
||||||
|
},
|
||||||
|
dragged: (x, y) => {
|
||||||
|
player.sceneRenderer.camera.screenToWorld(mouse.set(x, y, 0), player.canvas.clientWidth, player.canvas.clientHeight);
|
||||||
|
player.skeleton.getRootBone().x += mouse.x - last.x;
|
||||||
|
player.skeleton.getRootBone().y += mouse.y - last.y;
|
||||||
|
last.setFrom(mouse);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
frame: function (player, delta) {
|
||||||
|
player.skeleton.update(player.time.delta);
|
||||||
|
player.skeleton.updateWorldTransform(spine.Physics.update);
|
||||||
|
}
|
||||||
|
});</script>
|
||||||
|
</body></html>
|
||||||
@ -373,6 +373,7 @@ export class SpinePlayer implements Disposable {
|
|||||||
let time = animationDuration * percentage;
|
let time = animationDuration * percentage;
|
||||||
this.animationState!.update(time - this.playTime);
|
this.animationState!.update(time - this.playTime);
|
||||||
this.animationState!.apply(this.skeleton!);
|
this.animationState!.apply(this.skeleton!);
|
||||||
|
this.skeleton!.update(time - this.playTime);
|
||||||
this.skeleton!.updateWorldTransform(Physics.update);
|
this.skeleton!.updateWorldTransform(Physics.update);
|
||||||
this.playTime = time;
|
this.playTime = time;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user