사용자의 터치 위치를 지속적으로 얻으려면 어떻게해야합니까? 저는 게임용 콘트롤러에서 일하고 있습니다. 그리고 서있는 그대로 새로운 손가락을 올려서 개별적으로 움직여야 작동합니다. touchLocation 변수는 각 탭에서 업데이트되는 것만으로도 계속 업데이 트되는 것 같습니다. 따라서 손가락을 슬라이드해도 위치를 알고 적절하게 업데이트 할 수 있습니다. 다음은 관련 코드입니다. 고맙습니다!Cocos2d (IOS) - 사용자의 터치 위치를 지속적으로 얻으려면 어떻게해야합니까?
-(void)update:(CCTime)delta{
if([playerDirection isEqual:@"left"]){
_player.position = ccp(_player.position.x - 2, _player.position.y);
}
if([playerDirection isEqual:@"right"]){
_player.position = ccp(_player.position.x + 2, _player.position.y);
}
if([direction isEqual:@"up"]){
_enemy.position = ccp(_enemy.position.x, _enemy.position.y + 2);
}
if([direction isEqual:@"down"]){
_enemy.position = ccp(_enemy.position.x, _enemy.position.y - 2);
}
if(_enemy.position.y >= self.contentSize.height){
direction = @"down";
}
if(_enemy.position.y <= 2){
direction = @"up";
}
if(isTouching){
_player.position = ccp(_player.position.x + 2, _player.position.y);
}
}
// -----------------------------------------------------------------------
#pragma mark - Touch Handler
// -----------------------------------------------------------------------
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLocation = [touch locationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
if(touchLocation.x > 400){
playerDirection = @"right";
}
if(touchLocation.x < 200){
playerDirection = @"left";
}
CGPoint touchLoc = [touch locationInNode:self];
//isTouching = true;
// Log touch location
CCLOG(@"Move sprite to @ %@",NSStringFromCGPoint(touchLoc));
// Move our sprite to touch location
//CCActionMoveTo *actionMove = [CCActionMoveTo actionWithDuration:1.0f position:touchLoc];
//[_sprite runAction:actionMove];
}
- (void)touchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
playerDirection = @"none";
}