3

Im trying to show an enlarged preview of scene behind users finger when user presses the screen. Im extracting texture of node and adding it back to scene using below code

if let previewTexture = view?.textureFromNode(rootNode, crop: CGRect(origin: rootNodePoint, size: CGSize(width: 100, height: 100))) {
    previewNode.texture = previewTexture
}

When I use the method with crop rect its returning nil, but without the crop its returning the texture fine.

I cannot get the complete texture first and then crop it since the whole node tree could expand to more than 4098 points, and sprite kit returns empty texture in such case.

I cannot use the UIView drawViewHierarchyInRect method since it will return a snapshot with preview itself in it.

I have created a sample project to reproduce the issue TextureFromNodeBug

Update:

This problem is not getting replicated on iOS 9.2, so this could be a framework bug

Community
  • 1
  • 1
Tejesh Alimilli
  • 1,782
  • 1
  • 21
  • 31
  • It seems like you are going outside of the bounds of your node, crop needs a rectangle inside of rootNode's coordinate system,. so if rootNodePoint is a screen point instead of a point inside of rootNode, you will have issues. to test, crop with the bounds of the node, `CGRect(origin:CGPoint.zero, size:rootNode.size)` – Knight0fDragon Dec 03 '15 at 15:33
  • @Knight0fDragon I have tried it, didn't work – Tejesh Alimilli Dec 03 '15 at 16:33
  • did you verify if rootnode is the node that you want to grab? – Knight0fDragon Dec 03 '15 at 19:49
  • @Knight0fDragon as explained above, if I don't use crop Im getting back the texture I need. I just need a cropped version of it – Tejesh Alimilli Dec 04 '15 at 03:23
  • doesn't mean you are grabbing the correct node, rootnode implies you have nodes underneath it, now texture from node may grab the texture from all the nodes, crop may only grab from the the node that actually has the texture – Knight0fDragon Dec 04 '15 at 04:37
  • yes, rootNode has lot of other nodes and yes I need all that rendered as a texture. my goal is to convert full node hierarchy into texture object. as per apple docs crop should return a portion of the node hierarchy as texture, which doesn't seem to be working – Tejesh Alimilli Dec 04 '15 at 04:46
  • https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKView/index.html#//apple_ref/occ/instm/SKView/textureFromNode: says crop renders portion of node object, where without crop it renders the node tree – Knight0fDragon Dec 04 '15 at 05:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96945/discussion-between-tejesh-alimilli-and-knight0fdragon). – Tejesh Alimilli Dec 04 '15 at 05:10
  • I am having the same issue: Textures are `nil` on iOS 9.0 simulators, no problem on iOS 9.3. Dropping the `crop:` parameter fixes it, but I need to use it. – Nicolas Miari Apr 01 '16 at 12:01

0 Answers0