안녕하세요. 스택 오버플로가 좋은 사람들 오늘 (아주 좋지 않은) cocos2d 문제로 내가 서 있습니다.CCMoveTo 동안 타일 된 타일 맵의 충돌을 지속적으로 확인하는 방법
대상 타일을 확인하는 대신 작업에서 충돌을 어떻게 확인할 수 있습니까? 충돌 가능한 타일이있는 메타 레이어가있는 타일 맵으로 작업하고 있습니다. 다음 코드는 충돌 가능한 타일을 클릭 할 때 작동하지만 넘어서 클릭 할 때 작동하지 않습니다.
는 현재,이 코드와 충돌을 감지 :
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
[_player stopAllActions];
CGPoint touchLocation = [touch locationInView:touch.view];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
CGPoint playerPos = _player.position;
CGPoint diff = ccpSub(touchLocation, playerPos);
int diffx = diff.x;
int diffy = diff.y;
int adiffx = diffx/24;
int adiffy = diffy/24; //Porque my tile size is 24
if (abs(diff.x) > abs(diff.y)) {
if (diff.x > 0) {
playerPos.x = playerPos.x + adiffx * 24;
} else {
playerPos.x = playerPos.x + adiffx * 24;
}
} else {
if (diff.y > 0) {
playerPos.y = playerPos.y + adiffy * 24;
}else{
playerPos.y = playerPos.y + adiffy * 24;
}
}
[self setPlayerPosition:playerPos];
}
내가 운이없이
[self schedule:@selector(setPlayerPosition:) interval:0.5];
을 시도 :
-(void)setPlayerPosition:(CGPoint)position {
CGPoint tileCoord = [self tileCoordForPosition:position];
int tileGid = [_meta tileGIDAt:tileCoord];
if (tileGid) {
NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
if (properties) {
NSString *collision = properties[@"Collidable"];
if (collision && [collision isEqualToString:@"True"]) {
return;
}
}
}
float speed = 10;
CGPoint currentPlayerPos = _player.position;
CGPoint newPlayerPos = position;
double PlayerPosDifference = ccpDistance(currentPlayerPos, newPlayerPos)/24;
int timeToMoveToNewPostition = PlayerPosDifference/speed;
id moveTo = [CCMoveTo actionWithDuration:timeToMoveToNewPostition position:position];
[_player runAction:moveTo];
//_player.position = position;
}
그런데, 이것은이 방법에서 호출되는 앱이 즉시 앱을 즉시 추락 시켰습니다.
NSAssert(pos.x < _layerSize.width && pos.y < _layerSize.height && pos.x >=0 && pos.y >=0, @"TMXLayer: invalid position");
그리고 나는 그곳에서 충돌 한 것을 비난 할 수는 없습니다.
CCMoveTo
이 실행되는 동안 지속적으로 충돌 가능한 메타 타일과의 충돌을 확인하려면 어떻게해야합니까?
당신의 초기화에 –
아니, 내가 어떻게하는지 모른다 : D 당신은 나에게 계몽 할 수 있을까? @SmugbitStudios –