Saturday, April 13, 2024
HomeiOS Developmentios - SpriteKit: Resizing a SKShapeNode by person dragging

ios – SpriteKit: Resizing a SKShapeNode by person dragging


I am at present attempting to include resizing of an SKShapeNode by dragging the highest proper nook. One of many points that I am having is that I at present have the sq. capable of be dragged round by the person’s finger, and that is the place I am getting confused. How do I differentiate between when the person is altering the place of the form and when the person needs to resize the form?

class GameScene: SKScene {
    
    var sq.: SKShapeNode!
    
    override func didMove(to view: SKView) {
        // Create a sq.
        let squareSize = CGSize(width: 100, peak: 100)
        let squareRect = CGRect(origin: CGPoint(x: -squareSize.width / 2, y: -squareSize.peak / 2), dimension: squareSize)
        sq. = SKShapeNode(rect: squareRect, cornerRadius: 10)
        sq..fillColor = .blue
        sq..place = CGPoint(x: body.midX, y: body.midY)
        addChild(sq.)
    }
    
    override func touchesMoved(_ touches: Set<UITouch>, with occasion: UIEvent?) {
        // Get the contact location
        guard let contact = touches.first else { return }
        let touchLocation = contact.location(in: self)
        
        // Transfer the sq. to the contact location
        sq..place = touchLocation
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments