Created
February 15, 2015 05:17
-
-
Save ryantbrown/a7ab56091579a727c44c to your computer and use it in GitHub Desktop.
Working with sprite nodes in swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create image sprite | |
let img = SKSpriteNode(imageNamed:"ImageName"); | |
// scale the image | |
img.xScale = 0.5; | |
img.yScale = 0.5; | |
// set the image position | |
img.position = CGPoint(x: 100, y: 100); | |
// centering the image | |
img.position = CGpoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame)) | |
// determine the position from touch event | |
// must have access to touch (ie: func touchesBegan(touches: NSSet....) | |
img.position = touch.locationInNode(self); | |
// add sprite to view | |
self.addChild(sprite) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment