이 문제는 충분히 쉬운 것처럼 보입니다. 그러나 대답을 찾을 수 없으며 웹에서 답을 얻으려는 검색 용어가 일반적인 것처럼 보입니다. 그래서 도움이 되길 원합니다.배열에있는 객체의 메서드에 액세스합니다.
나는 신속한에서 SKSpriteNode
객체 : 일부 노드를 추가
var images:[SKSpriteNode] = [];
: 나는의 액세스 방법을있을 때
images+=[SKSpriteNode(imageNamed: "StarrySky")];
images+=[SKSpriteNode(imageNamed: "StarrySky")];
images+=[SKSpriteNode(imageNamed: "StarrySky")];
images+=[SKSpriteNode(imageNamed: "StarrySky")];
는 지금은 일치하지 않는 결과를 얻을 수함께 : 예를 들어
images[0].position
: 때때로 작동
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);
}
, 다른 시간 엑스 코드는 Could not find member position
을 말하고있다. 배열에 SKSpriteNode
대신에 position
이라는 멤버가 없다는 것을 알았습니다.
내가 어떻게 배열 자체가 아니라 배열에있는 개체의 메서드를 지정하는 모든 아이디어?
비고 : 당신이
이을 단축 할 경우
다음 사용자 정의
+
연산자를 정의해야 스위프트 언어에서 세미콜론을 필요로하지 않습니다 성명서의 끝. –고마워요 - 실제로는 세미콜론은 선택 사항이며 계속 사용하기로 결정했습니다. xcode가 자동으로 줄을 나누면 명령의 끝인지 쉽게 알 수 있습니다. – TPot