London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
2 C
New York
Wednesday, January 29, 2025

ios – iPhone SpriteKit rotation and zooming


I’m new to SpriteKit, and I’m making an attempt to follow by making a easy 2D sport. I’ve gotten as far as to have my map displayed on the display screen, and cropped to solely fill about 1/3 of the display screen (in order that I can go away area for different controls, and so on).

Nevertheless, making use of the rotation and zooming in gestures to the map are giving me a headache. I’ve discovered that if I rotate the digital camera (SKCameraNode), then my entire display screen rotates, and that isn’t what I would like. You’ll be able to see my try at: https://youtu.be/UHIifaoGQQw if you wish to. Within the video, I would just like the map to rotate and zoom inside the inexperienced rectangle, and be cropped neatly inside the inexperienced rectangle solely. However as you’ll be able to see, the entire thing rotates.

I attempted to position my SKCameraNode contained in the SKCropNode, however that did not assist.

Additionally, I’ve tried to use rotations to my SKTileMapNode object, and that’s truly working accurately and cropping the seen map space to 1/3 of the display screen. Nevertheless, the rotation doesn’t appear to be centered across the consumer’s middle view, and the axis of rotation is all the time considerably left or proper of the considered map middle. This makes it very onerous to rotate and zoom the map in any helpful means.

Is there any solution to make the most of SKCameraNode and have it cropped “accurately”? If I rotate the entire SKTileMapNode, then I would wish to do some superior arithmetic to calculate the brand new place of the SKTileMapNode after rotation, as a way to middle it to the view, and it appears to be very onerous for me (not a math buff right here, sorry).

That is how I render my map:

personal func renderMap() {
  guard let map = currentMap else { return }
  guard let textureAtlas = textureAtlas else {
    print("Texture atlas not loaded")
    return
  }
  let tileSet = createTileSet(from: textureAtlas)
  let columns = map.mapData[0].rely
  let rows = map.mapData.rely
  let tileMap = SKTileMapNode(tileSet: tileSet, columns: columns, rows: rows, tileSize: tileSize)
  tileMap.anchorPoint = CGPoint(x: 0.5, y: 0.5)  
  // Fill the tile map with tiles primarily based on the mapData
  for row in 0 ..< rows {
    for column in 0 ..< columns {
      let tileName = map.mapData[row][column]
      if let tileGroup = tileSet.tileGroups.first(the place: { $0.identify == tileName }) {
        tileMap. setTileGroup(tileGroup, forColumn: column, row: row)
      }
    }
  }
  // Create a crop node
  let cropNode = SKCropNode()
  let cropWidth = tileSize.width * 3
  let maskNode = SKShapeNode(rect: CGRect(x: 0, y: 0, width: cropWidth, peak: 300))
  maskNode.fillColor = .white
  cropNode.maskNode = maskNode
  cropNode.addChild(tileMap)
  self.addChild(cropNode)
}

Right here is my rotation handler:

// Deal with rotation
@objc personal func handleRotation(gesture: UIRotationGestureRecognizer) {
  print("handleRotation")
  guard let digital camera = digital camera else { return }
  if gesture. state == .modified | | gesture.state == .ended {
  digital camera.zRotation -= gesture.rotation
  gesture.rotation = 0.0 // Reset rotation issue
  print("handleRotation full")
}

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com