Skip to content

Instantly share code, notes, and snippets.

@ryantbrown
Created February 15, 2015 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryantbrown/a7ab56091579a727c44c to your computer and use it in GitHub Desktop.
Save ryantbrown/a7ab56091579a727c44c to your computer and use it in GitHub Desktop.
Working with sprite nodes in swift
// 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