This problem seems easy enough, but I can't find the answer and my search terms seem to generic to get an answer from the web - hoping SO can help:
I've created an array of SKSpriteNode objects in swift:
var images:[SKSpriteNode] = [];
I add some nodes:
images+=[SKSpriteNode(imageNamed: "StarrySky")];
images+=[SKSpriteNode(imageNamed: "StarrySky")];
images+=[SKSpriteNode(imageNamed: "StarrySky")];
images+=[SKSpriteNode(imageNamed: "StarrySky")];
Now I get inconsistent results when I'm access methods of the SKSpriteNode with:
images[0].position
For example:
func moveBackground(direction: CGVector) {
//works
let origin = images[0].position;
var newPoint = CGPoint(x: origin.x + direction.dx, y: origin.y + direction.dy);
positionBackground(newPoint);
//next line has a compilation error.
positionBackground(images[0].position + direction);
}
Sometimes it it works, other times xCode is saying Could not find member position. I figure it's saying the array doesn't have a member position, instead of the SKSpriteNode.
Any idea how I specify it's a method of the object in the array itself and not the array?