mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Update SpineView & SpineView.Builder API
This commit is contained in:
parent
01a6952ff5
commit
fc4716f749
@ -133,14 +133,13 @@ fun AnimationState(nav: NavHostController) {
|
|||||||
) {
|
) {
|
||||||
Text("See output in console!")
|
Text("See output in console!")
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { context ->
|
||||||
SpineView(ctx).apply {
|
SpineView.loadFromAssets(
|
||||||
loadFromAsset(
|
"spineboy.atlas",
|
||||||
"spineboy.atlas",
|
"spineboy-pro.json",
|
||||||
"spineboy-pro.json",
|
context,
|
||||||
controller
|
controller
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,21 +42,20 @@ fun DebugRendering(nav: NavHostController) {
|
|||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { context ->
|
||||||
SpineView(ctx).apply {
|
SpineView.loadFromAssets(
|
||||||
loadFromAsset(
|
"spineboy.atlas",
|
||||||
"spineboy.atlas",
|
"spineboy-pro.json",
|
||||||
"spineboy-pro.json",
|
context,
|
||||||
SpineController.Builder()
|
SpineController.Builder()
|
||||||
.setOnInitialized {
|
.setOnInitialized {
|
||||||
it.animationState.setAnimation(0, "walk", true)
|
it.animationState.setAnimation(0, "walk", true)
|
||||||
}
|
}
|
||||||
.setOnAfterPaint { controller, canvas, commands ->
|
.setOnAfterPaint { controller, canvas, commands ->
|
||||||
debugRenderer.render(controller.drawable, canvas, commands)
|
debugRenderer.render(controller.drawable, canvas, commands)
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier = Modifier.padding(paddingValues)
|
modifier = Modifier.padding(paddingValues)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -163,10 +163,8 @@ fun DressUp(nav: NavHostController) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { context ->
|
||||||
SpineView(ctx).apply {
|
SpineView.loadFromDrawable(drawable, context, controller)
|
||||||
loadFromDrawable(drawable, controller)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier = Modifier.padding(paddingValues)
|
modifier = Modifier.padding(paddingValues)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -95,14 +95,13 @@ fun IKFollowing(nav: NavHostController) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { context ->
|
||||||
SpineView(ctx).apply {
|
SpineView.loadFromAssets(
|
||||||
loadFromAsset(
|
"spineboy.atlas",
|
||||||
"spineboy.atlas",
|
"spineboy-pro.json",
|
||||||
"spineboy-pro.json",
|
context,
|
||||||
controller
|
controller
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,14 +110,13 @@ fun Physics(nav: NavHostController) {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { context ->
|
||||||
SpineView(ctx).apply {
|
SpineView.loadFromAssets(
|
||||||
loadFromAsset(
|
"celestial-circus.atlas",
|
||||||
"celestial-circus.atlas",
|
"celestial-circus-pro.skel",
|
||||||
"celestial-circus-pro.skel",
|
context,
|
||||||
controller
|
controller
|
||||||
)
|
)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier = Modifier.padding(paddingValues)
|
modifier = Modifier.padding(paddingValues)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -62,16 +62,10 @@ fun PlayPause(
|
|||||||
|
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { ctx ->
|
||||||
SpineView.Builder(ctx)
|
SpineView.Builder(ctx, controller)
|
||||||
|
.setLoadFromAssets("dragon.atlas", "dragon-ess.skel")
|
||||||
.setBoundsProvider(SkinAndAnimationBounds("flying"))
|
.setBoundsProvider(SkinAndAnimationBounds("flying"))
|
||||||
.build()
|
.build()
|
||||||
.apply {
|
|
||||||
loadFromAsset(
|
|
||||||
"dragon.atlas",
|
|
||||||
"dragon-ess.skel",
|
|
||||||
controller
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier = Modifier.padding(paddingValues)
|
modifier = Modifier.padding(paddingValues)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -35,18 +35,17 @@ fun SimpleAnimation(nav: NavHostController) {
|
|||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
AndroidView(
|
AndroidView(
|
||||||
factory = { ctx ->
|
factory = { context ->
|
||||||
SpineView(ctx).apply {
|
SpineView.loadFromAssets(
|
||||||
loadFromAsset(
|
"spineboy.atlas",
|
||||||
"spineboy.atlas",
|
"spineboy-pro.json",
|
||||||
"spineboy-pro.json",
|
context,
|
||||||
SpineController.Builder()
|
SpineController.Builder()
|
||||||
.setOnInitialized {
|
.setOnInitialized {
|
||||||
it.animationState.setAnimation(0, "walk", true)
|
it.animationState.setAnimation(0, "walk", true)
|
||||||
}
|
}
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
}
|
|
||||||
},
|
},
|
||||||
modifier = Modifier.padding(paddingValues)
|
modifier = Modifier.padding(paddingValues)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -54,11 +54,24 @@ public class SpineView extends View implements Choreographer.FrameCallback {
|
|||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
|
private final SpineController controller;
|
||||||
|
|
||||||
|
private String atlasFileName;
|
||||||
|
|
||||||
|
private String skeletonFileName;
|
||||||
|
|
||||||
private BoundsProvider boundsProvider = new SetupPoseBounds();
|
private BoundsProvider boundsProvider = new SetupPoseBounds();
|
||||||
private Alignment alignment = Alignment.CENTER;
|
private Alignment alignment = Alignment.CENTER;
|
||||||
|
|
||||||
public Builder(Context context) {
|
public Builder(Context context, SpineController controller) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setLoadFromAssets(String atlasFileName, String skeletonFileName) {
|
||||||
|
this.atlasFileName = atlasFileName;
|
||||||
|
this.skeletonFileName = skeletonFileName;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setBoundsProvider(BoundsProvider boundsProvider) {
|
public Builder setBoundsProvider(BoundsProvider boundsProvider) {
|
||||||
@ -72,9 +85,12 @@ public class SpineView extends View implements Choreographer.FrameCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SpineView build() {
|
public SpineView build() {
|
||||||
SpineView spineView = new SpineView(context);
|
SpineView spineView = new SpineView(context, controller);
|
||||||
spineView.boundsProvider = boundsProvider;
|
spineView.boundsProvider = boundsProvider;
|
||||||
spineView.alignment = alignment;
|
spineView.alignment = alignment;
|
||||||
|
if (atlasFileName != null && skeletonFileName != null) {
|
||||||
|
spineView.loadFromAsset(atlasFileName, skeletonFileName);
|
||||||
|
}
|
||||||
return spineView;
|
return spineView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,35 +113,50 @@ public class SpineView extends View implements Choreographer.FrameCallback {
|
|||||||
|
|
||||||
Alignment alignment = Alignment.CENTER;
|
Alignment alignment = Alignment.CENTER;
|
||||||
|
|
||||||
public SpineView (Context context) {
|
public SpineView (Context context, SpineController controller) {
|
||||||
super(context);
|
super(context);
|
||||||
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpineView (Context context, AttributeSet attrs) {
|
public SpineView (Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
this.controller = new SpineController();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpineView (Context context, AttributeSet attrs, int defStyle) {
|
public SpineView (Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
|
this.controller = new SpineController();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFromAsset(String atlasFileName, String skeletonFileName, SpineController controller) {
|
public static SpineView loadFromAssets(String atlasFileName, String skeletonFileName, Context context, SpineController controller) {
|
||||||
|
SpineView spineView = new SpineView(context, controller);
|
||||||
|
spineView.loadFromAsset(atlasFileName, skeletonFileName);
|
||||||
|
return spineView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpineView loadFromDrawable(AndroidSkeletonDrawable drawable, Context context, SpineController controller) {
|
||||||
|
SpineView spineView = new SpineView(context, controller);
|
||||||
|
spineView.loadFromDrawable(drawable);
|
||||||
|
return spineView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setController(SpineController controller) {
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFromAsset(String atlasFileName, String skeletonFileName) {
|
||||||
loadFrom(() -> AndroidSkeletonDrawable.fromAsset(atlasFileName, skeletonFileName, getContext()));
|
loadFrom(() -> AndroidSkeletonDrawable.fromAsset(atlasFileName, skeletonFileName, getContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFromFile(File atlasFile, File skeletonFile, SpineController controller) {
|
public void loadFromFile(File atlasFile, File skeletonFile) {
|
||||||
this.controller = controller;
|
|
||||||
loadFrom(() -> AndroidSkeletonDrawable.fromFile(atlasFile, skeletonFile));
|
loadFrom(() -> AndroidSkeletonDrawable.fromFile(atlasFile, skeletonFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFromHttp(URL atlasUrl, URL skeletonUrl, SpineController controller) {
|
public void loadFromHttp(URL atlasUrl, URL skeletonUrl) {
|
||||||
this.controller = controller;
|
|
||||||
loadFrom(() -> AndroidSkeletonDrawable.fromHttp(atlasUrl, skeletonUrl));
|
loadFrom(() -> AndroidSkeletonDrawable.fromHttp(atlasUrl, skeletonUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFromDrawable(AndroidSkeletonDrawable drawable, SpineController controller) {
|
public void loadFromDrawable(AndroidSkeletonDrawable drawable) {
|
||||||
this.controller = controller;
|
|
||||||
loadFrom(() -> drawable);
|
loadFrom(() -> drawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user