0
화면 절반을 두드린 후 노드의 위치를 변경하려고합니다. 노드가 그들 사이를 이동하기를 원한다면 정확한 3 점을 얻었습니다. 노드가 어디에 있는지를 탐지하기 위해 BOOL을 만들었습니다.SpriteKit 터치 후 위치 변경
내 코드가 올바르게 작동하지 않습니다. 노드가 포인트 3에 있고 화면의 왼쪽을 탭하면 포인트 1이 아닌 포인트 2로 이동합니다. 업데이트 방법을 변경하면 Node.position.x ==로 (self.frame.size.width/2), 노드는 포인트 1 점 3.
@implementation MyScene {
BOOL Point1;
BOOL Point2;
BOOL Point3;
}
-(void)Node {
Node = [SKSpriteNode spriteNodeWithTexture:Node1];
Node.size = CGSizeMake(50, 50);
Node.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/3);
Node.zPosition = 4;
[self addChild:Node];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];
// If left half of the screen is touched
if (touchLocation.x < self.size.width/2) {
if(Point2 == YES){
Node.position = CGPointMake(self.frame.size.width/3.5, self.frame.size.height/3);
}
if(Point3 == YES){
Node.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/3);
}
}
// If right half of the screen is touched
if (touchLocation.x > self.size.width/2) {
if(Point1 == YES){
Node.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/3);
}
if(Point2 == YES){
Node.position = CGPointMake(self.frame.size.width/1.4, self.frame.size.height/3);
}
}
}
-(void)update:(CFTimeInterval)currentTime {
/* Called before each frame is rendered */
if(Node.position.x >= (self.frame.size.width/1.4)){
Point1 = true;
Point2 = false;
Point3 = false;
}
else if(Node.position.x >= (self.frame.size.width/2)){
Point1 = false;
Point2 = true;
Point3 = false;
}
else if(Node.position.x >= (self.frame.size.width/3.5)){
Point1 = false;
Point2 = false;
Point3 = true;
} }
체크 아웃 로직이> = 또는 = <또는 결합이> = 또는 = 모든 상태를 점검하여 통해 UR 상황에서 ==를 사용할 수 없습니다 잘못 이잖아 다음은
UpdateMethod
의 작업 코드는 < – dragoneye문제가 업데이트되었습니다. 도와 주셔서 감사합니다! –
나는 (Point1 == YES) if를 사용하는 것이 좋습니다. 프로그램을 해킹하기가 더 어려워집니다. – helloGo