EsotericSoftware / spine-runtimes

2D skeletal animation runtimes for Spine.
http://esotericsoftware.com/
Other
4.35k stars 2.89k forks source link

[cocos2dx] How does iOS spine-cocos2d-objc fit scale and screen #1798

Closed XGCoder closed 3 years ago

XGCoder commented 3 years ago
CGFloat scale =  1;     
// 获取动画 (Get the animation )
skeletonNode = [SkeletonAnimation skeletonWithFile:@"test.json" atlasFile:@"test.atlas" scale:scale];

// 读取动画名称并运行动画 (Read the animation name and run the animation)
spAnimation * spAnimation = skeletonNode.state->data->skeletonData->animations[0];
NSString * animationName = [NSString stringWithUTF8String:spAnimation->name];
[skeletonNode addAnimationForTrack:0 name:animationName loop:YES afterDelay:0.0];

[skeletonNode setScale:scale];
CGSize windowSize1 = CGSizeMake(ScreenWidth, ScreenHeight);
CGSize windowSize2 = [[CCDirector sharedDirector] viewSize];
self.contentSize = windowSize1;

I downloaded the project and showed the sample program using spine-Cocos2D-objc, but after switching to our resource, I found that it was not possible to display our spine animation in full screen during the presentation, and I had two problems

  1. How can the scale here be adapted according to the screen?
  2. How to get the size of an image resource through OC code?

我下载了此项目并使用spine-cocos2d-objc展示了示例程序,但是切换为我们的资源后,在展示时发现无法全屏展示我们的spine动画,我有两个问题

  1. 这里的scale怎么根据屏幕进行适配呢?
  2. 通过oc代码 怎么获取某个图片资源的尺寸?
badlogic commented 3 years ago

Spine skeletons are modelled in pixels. The scales used in the example project are manually chosen so that the skeletons fit on screen.

You can query the size of a skeleton after it is loaded via soSkeletonData, which is set on spSkeleton which itself can be found on the SkeletonAnimation Obj-C class. https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-c/spine-c/include/spine/SkeletonData.h#L50

For further questions, please use our forums at https://esotericsoftware.com/forum

XGCoder commented 3 years ago

脊柱骨骼以像素为模型。手动选择示例项目中使用的比例,以使骨架适合屏幕。

您可以查询它通过加载后骨骼的大小soSkeletonData,这是设置在spSkeleton其本身可以在找到SkeletonAnimation的OBJ-C类。https://github.com/EsotericSoftware/spine-runtimes/blob/3.8/spine-c/spine-c/include/spine/SkeletonData.h#L50

如有其他疑问,请在https://esotericsoftware.com/forum上使用我们的论坛。

Thanks for your reply. What I found in 'spSkeletonData' is indeed the size of the entire canvas, but my need is to get the size of a particular image When I get a 'Slot size' from the 'SkeletonRenderer' 'findSlot' method, I don't find a 'Slot size' method

感谢回复,我在spSkeletonData 中找到的确实是整个画布的尺寸,但是,我的需求是想要获取某个图片的尺寸 我在通过 SkeletonRendererfindSlot方法获取某个Slot的尺寸的时候,并没有发现有关Slot尺寸的方法