mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[android] Fixes #2682, remove frame callback if view is no longer attached to window.
This commit is contained in:
parent
d3f7483dbe
commit
8c37b4cc68
@ -181,6 +181,8 @@ public class SpineView extends View implements Choreographer.FrameCallback {
|
||||
private Alignment alignment = Alignment.CENTER;
|
||||
private ContentMode contentMode = ContentMode.FIT;
|
||||
|
||||
private boolean isAttached = false;
|
||||
|
||||
/** Constructs a new {@link SpineView}.
|
||||
*
|
||||
* After initialization is complete, the provided {@code SpineController} is invoked as per the {@link SpineController}
|
||||
@ -208,6 +210,18 @@ public class SpineView extends View implements Choreographer.FrameCallback {
|
||||
// Set properties by view id
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow () {
|
||||
super.onAttachedToWindow();
|
||||
isAttached = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow () {
|
||||
super.onDetachedFromWindow();
|
||||
isAttached = false;
|
||||
}
|
||||
|
||||
/** Constructs a new {@link SpineView} from files in your app assets. The {@code atlasFileName} specifies the `.atlas` file to
|
||||
* be loaded for the images used to render the skeleton. The {@code skeletonFileName} specifies either a Skeleton `.json` or
|
||||
* `.skel` file containing the skeleton data.
|
||||
@ -407,10 +421,9 @@ public class SpineView extends View implements Choreographer.FrameCallback {
|
||||
controller.setCoordinateTransform(x + offsetX / scaleX, y + offsetY / scaleY, scaleX, scaleY);
|
||||
}
|
||||
|
||||
// Choreographer.FrameCallback
|
||||
|
||||
@Override
|
||||
public void doFrame (long frameTimeNanos) {
|
||||
if (!isAttached) return;
|
||||
if (lastTime != 0) delta = (frameTimeNanos - lastTime) / 1e9f;
|
||||
lastTime = frameTimeNanos;
|
||||
invalidate();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user