Swift, SpriteKit: Drawing with an SKTexture

Discussion in 'iOS Programming' started by Milese3, Sep 4, 2014.

  1. Milese3 macrumors 6502

    Joined:
    Aug 11, 2014
    Location:
    Southampton - United Kingdom
    #1
    Hi, I would like to know how I can use the TouchesMoved function in Swift to draw an SKTexture (in my case, a ladder texture) where the user drew.

    King regards, Miles.
     
  2. omenatarhuri, Sep 8, 2014
    Last edited by a moderator: Sep 8, 2014

    omenatarhuri macrumors 6502a

    Joined:
    Feb 9, 2010
    #2
    Hey,

    Something like this should work?

    Code:
    override func touchesMoved(touches: NSSet, withEvent event: UIEvent)
        {
            for touch: AnyObject in touches
            {
                let location = touch.locationInNode(self)
                drawMyAwesomeLadder(location)
            }
        }
          
    func drawMyAwesomeLadder(location : CGPoint)
    {
              var newNode = SKSpriteNode(texture: SKTexture(imageNamed: "ladder"))
            newNode.position = location
            view.addChild(newNode) // view here is your SKView
    }
    Oops, it was 4 days ago, I suppose you solved it already. :)
     

Share This Page