I'm currently using Metal to create a game board with floating balloons; each balloon is a SKSpriteNode with an image of a balloon attached. The user touches and drags the balloon to a second balloon, merging the two. Exactly how they get merged is based on input from the user. I have a UISegmentedControl that pops up where the user selects one of four responses and the merge occurs. Currently, the UISegmentedControl pops up in the middle of the game board; however, I would like it to overlay on top of the first balloon instead.
I have tried this once the two balloons touch each other:
bubble1.physicsBody!.velocity = CGVector(dx: 0, dy: 0) // Stopping the balloon
requestView.frame.origin.x = bubble1.position.x
requestView.frame.origin.y = bubble1.position.y
Where requestView is a UIView (with the same dimensions of the balloon) with various subviews (including the UISegmentedControl) and bubble1 is the SKSpriteNode (balloon). However, when I add the requestView as a subview of the game board, it does not overlay on top of the SKSpriteNode (bubble1). In fact, each time I try it, it doesn't even seem to appear in the same space relative to the location of the bubble1. Any thoughts on what I might be doing wrong? Thanks!
UIKituses screen coordinates whileMetaluses clip-spaced coordinates.Here are functions that convert
UIKitcoordinates toMetal:Convert screen coordinates to Metal's Normalized Device Coordinates
You will need to do the inverse to convert
MetaltoUIKit. Something like this:This may be helpful too: translate between NSView and MTL drawable coordinates