mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-01 13:19:08 +08:00
[ios] Add boundsProvider to renderToImage (#3002)
This commit is contained in:
parent
6968ebd8e8
commit
0fa873e3d9
@ -22,3 +22,4 @@
|
||||
- Add option to disable drawing when out of viewport (#18)
|
||||
- Add docs for public Spine classes/methods (#19)
|
||||
- Fix various regressions (#20)
|
||||
- Add `boundsProvider` parameter to `SkeletonDrawableWrapper.renderToImage(...)` to align image rendering bounds with `SpineView` (#3002)
|
||||
|
||||
@ -58,7 +58,7 @@ struct DressUp: View {
|
||||
SpineView(
|
||||
from: .drawable(drawable),
|
||||
controller: model.controller,
|
||||
boundsProvider: SkinAndAnimationBounds(skins: ["full-skins/girl"])
|
||||
boundsProvider: model.boundsProvider
|
||||
)
|
||||
} else {
|
||||
Spacer()
|
||||
@ -76,6 +76,7 @@ struct DressUp: View {
|
||||
final class DressUpModel: ObservableObject {
|
||||
|
||||
let thumbnailSize = CGSize(width: 200, height: 200)
|
||||
let boundsProvider: BoundsProvider = SkinAndAnimationBounds(skins: ["full-skins/girl"])
|
||||
|
||||
@Published
|
||||
var controller: SpineController
|
||||
@ -118,6 +119,7 @@ final class DressUpModel: ObservableObject {
|
||||
try skin.name.flatMap { skinName in
|
||||
self.skinImages[skinName] = try drawable.renderToImage(
|
||||
size: self.thumbnailSize,
|
||||
boundsProvider: self.boundsProvider,
|
||||
backgroundColor: .white,
|
||||
scaleFactor: UIScreen.main.scale
|
||||
)
|
||||
|
||||
@ -37,11 +37,18 @@ public extension SkeletonDrawableWrapper {
|
||||
///
|
||||
/// Parameters:
|
||||
/// - size: The size of the `CGImage` that should be rendered.
|
||||
/// - boundsProvider: The skeleton bounds provider used to compute fitting and positioning.
|
||||
/// - backgroundColor: the background color of the image
|
||||
/// - scaleFactor: The scale factor. Set this to `UIScreen.main.scale` if you want to show the image in a view
|
||||
func renderToImage(size: CGSize, backgroundColor: UIColor, scaleFactor: CGFloat = 1) throws -> CGImage? {
|
||||
func renderToImage(
|
||||
size: CGSize,
|
||||
boundsProvider: BoundsProvider = SetupPoseBounds(),
|
||||
backgroundColor: UIColor,
|
||||
scaleFactor: CGFloat = 1
|
||||
) throws -> CGImage? {
|
||||
let spineView = SpineUIView(
|
||||
controller: SpineController(disposeDrawableOnDeInit: false), // Doesn't own the drawable
|
||||
boundsProvider: boundsProvider,
|
||||
backgroundColor: backgroundColor
|
||||
)
|
||||
spineView.frame = CGRect(origin: .zero, size: size)
|
||||
|
||||
@ -46,7 +46,7 @@ import UIKit
|
||||
/// To update the ``AnimationState`` and apply it to the ``Skeleton`` call the ``AnimationStateWrapper/update`` function, providing it
|
||||
/// a delta time in seconds to advance the animations.
|
||||
///
|
||||
/// To render the current pose of the ``Skeleton`` as a `CGImage`, use ``SkeletonDrawableWrapper/renderToImage(size:backgroundColor:scaleFactor:)``.
|
||||
/// To render the current pose of the ``Skeleton`` as a `CGImage`, use ``SkeletonDrawableWrapper/renderToImage(size:boundsProvider:backgroundColor:scaleFactor:)``.
|
||||
///
|
||||
/// When the skeleton drawable is no longer needed, call the ``SkeletonDrawableWrapper/dispose()`` method to release its resources. If
|
||||
/// the skeleton drawable was constructed from a shared ``Atlas`` and ``SkeletonData``, make sure to dispose the
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user