3

I'm making a game using Objective-C and Sprite Kit and I've encountered a problem I can't get a workaround for so after hours of trying myself, I've considered asking you here.

I've created an animation using CoreAnimator and the result is given as an UIView object. I've added the object as a subview for my main view in the GameViewController and it is displayed and animated correctly. But now I would like to link it with another object.

Previously when I was just using a placeholder animation, I used it as a regular SKSpriteNode so if object A was an SKNode then we could link them together simply by using [objectA addChild:objectB]. That worked really fine and I would like to keep it that way. But now since objectB is no longer a node, but a UIView I can't really use addChild anymore.

Can you know or can think of any workaround for this problem?

GameScene:

Parent:

_objectA = [[SKNode alloc] init];
_objectA.position = CGPointMake([[UIScreen mainScreen] bounds].size.width * -0.35,
[[UIScreen mainScreen] bounds].size.height * -0.26);
_objectA.zPosition = 0.9;
[_worldContainer addChild:_objectA];

Child:

_objectB = [self.view viewWithTag:123];
[_objectB addTopAnimation];

GameViewController:

_objectB = [[TestAnimView alloc] init];
_objectB.tag = 123;
_objectB.transform = CGAffineTransformMakeScale(0.6, 0.6);
_objectB.layer.anchorPoint = CGPointMake(0.5, 0);
_objectB.layer.position = CGPointMake([[UIScreen mainScreen] bounds].size.width * 0.139,[[UIScreen mainScreen] bounds].size.height * 0.49);
[self.view addSubview:_objectB];
Hamish
  • 78,605
  • 19
  • 187
  • 280
Sisik2205
  • 41
  • 3
  • 1
    You've answered your own question. You can't add an UIView instance as a child of SKNode. You can add it as a subview to some other view. – Whirlwind Jan 17 '16 at 22:15
  • you could add the `UIView` as a child to the `SKView`.... but honestly I think you should look at implementing your animation into Sprite Kit, instead of an SK-UIKit hybrid. – Hamish Jan 17 '16 at 22:19
  • Yeah I know that it can't be done easily, that's why I'm asking if anyone have any idea for a workaround. It can even be super twisted as long as it works. But yeah maybe it will be a better solution to find some other app that will export a project to something that works better with SpriteKit. – Sisik2205 Jan 17 '16 at 22:22
  • `UIView` and `SKNode` have no relationship, you are trying to breed dogs and cats here. Best you can do is capture the animation frame by frame, and turn them into textures. If your objects require moving of the actual object, then you will have to take note of these movements and translate it into `SKActions` or something. – Knight0fDragon Jan 19 '16 at 19:29

0 Answers0