Reputation: 55
Im trying to add an image to a specific coordinate on the view controller, I already imported SpriteKit to see if that could help. I just need to add the image and be able to move it on a UIBezierPath but it wont let me add Child.
var blueDot = SKSpriteNode()
var blackDot = SKSpriteNode()
var levelLabelInt = levelLabel.text!.toInt()
var blueDotTexture = SKTexture(imageNamed: "Sprites.atlas/BlueDot.png")
blueDot = SKSpriteNode(texture: blueDotTexture)
blueDot.position = CGPoint(x: (50), y: levelLabelInt! + 100)
self .addChildViewController: ViewController (blueDot)
Upvotes: 0
Views: 4474
Reputation: 1714
By looking at the code
above, one of your issues is a space between self
and .addChildViewController
In Swift to send a message to self
you have to use .dotSyntax. and the addChild()
function requires an argument of type UIViewController
self.addChild(blueDot)
syntax is correct but blueDot is of type: SKNode
and SKNode
doesn't inherit from UIViewController so you can't pass that argument.
I suggest you do this instead:
let image = UIImage(named: "Sprites.atlas/BlueDot.png")
let imageView = UIImageView(image: image)
self.view.addSubview(imageView)
Now you have an image inside your ViewController's views hierarchy or as you prefer to refer to it: a child object inside your parent object.
Upvotes: 1