경로가 상단에서부터 아래로 스크롤되는 iOS 무한 러너 게임이 있습니다.iOS Endless Runner Lag SpriteKit
다음과 같습니다 : 2 개의 스프라이트가 생성되고 첫 번째 스프라이트가 화면에서 사라지면 이미지에서 다른 스프라이트를로드하고 동일한 로직을 실행합니다.
문제 : 첫 번째 스프라이트가 사라지고 새 것이 나타나는 즉시 작은 지체가 있습니다.
편집 :이 문제는 iPhone 5에서 실행될 때만 발생합니다. iPhone 4는 완벽하게 작동합니다!
누구든지 아이디어가 있습니까? 또는이 문제가 발생하여 해결 되었습니까?
if (CurrentObstacle.frame.origin.y < -self.frame.size.height + 10) {
// clear old obstacle
CurrentObstacle = nil;
CurrentObstacle = nextObstacle;
currentObstacleImage = nextObstacleImage; // for pixel processing stuff
[self generateObstacle];
}
- (void)generateObstacle{
// genrate random image name
int i = rand()%10+1;
NSString *imageName = [NSString stringWithFormat:@"ob%i", i];
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
if(screenSize.height == 480)
{
//Load 3.5 size
imageName = [imageName stringByAppendingString:@"small"];
}
imageName = [imageName stringByAppendingString:@".png"];
// create obstacle
nextObstacle = [SKSpriteNode spriteNodeWithImageNamed:imageName];
nextObstacleImage = [imageDictionary objectForKey:imageName];
nextObstacle.size = self.size;
nextObstacle.position = CGPointMake(self.view.center.x, 1.48*nextObstacle.size.height);
// set speed to be the same as the other obstacles
nextObstacle.speed = CurrentObstacle.speed;
// show obstacle
[self addChild:nextObstacle];
// move obstacle
SKAction *moveAction = [SKAction moveByX:0 y:-2*self.size.height-1 duration:8];
[nextObstacle runAction:moveAction];
}
항상 다음에로드 할 수 있도록 사전로드하십시오. –
적어도 스프라이트를 바꾸기 위해 실행 한 코드를 게시하십시오. 정확히 무엇을하고 있는지 알 수 없다면 진단 할 수 없습니다. – LearnCocos2D
방금 코드를 추가했습니다. @SantaClaus 문제가 아니라고 생각합니다. 문제는 화면에 나타나는 개체와 관련이 있다고 생각합니다. iPhone 4에서는 제대로 작동하기 때문에 iPhone 5에서는 사용할 수 없습니다. – Ahmed