Rotate a sprite to sprite position not exact in SpriteKit with Swift

后端 未结 3 410
既然无缘
既然无缘 2021-01-13 02:33

I\'m trying to rotate a player to the touch. Using the touches move function, I set the location to a variable. I then call a function. It works but the angle is off. Locati

3条回答
  •  自闭症患者
    2021-01-13 03:10

    Try something like this

    //set sprite to image
    
    
    
    Person = SKSpriteNode(imageNamed: "Person")
    
    
    
    
        //set size
        Person.size = CGSize(width: 40, height: 7)
    
    
    
        //set position
        Person.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2 + 120)
    
    
    
    
    
        //rotate node 3.14 / 2 = to 90 degree angle
        Person.zRotation = 3.14 / 2
    
    
    
        Person.zPosition = 2.0
    

提交回复
热议问题