I have an issue with my scrolling Background (WAVE) for a game I'm developing in Objective C Sprite Kit framework. I'm using a method from the book 'iOS Games by tutorials' (highly recommended- very informative book) as a guideline, as I'm new to it.
I got everything to work fine, but after I close the game.. and my iPhone been sitting for right around 20-30 minutes - I come back to the game and the Scrolling BG is blank for 5-15 seconds then it loads and scrolls. Oddly, when I first test the game - it loads immediately no issues. I also have nodes / graphics and they all load quickly each and every time no issues.
다음은 매 프레임 업데이트되는 주요 코드 스 니펫입니다.
- (void)moveWave
{
CGPoint waveVelocity = CGPointMake(-wave_speed, 0);
CGPoint amtToMove = CGPointMultiplyScalar(waveVelocity, _dt);
_waveLayer.position = CGPointAdd(_waveLayer.position, amtToMove);
[_waveLayer enumerateChildNodesWithName:@"wave"
usingBlock:^(SKNode *node, BOOL *stop){
SKSpriteNode * wave = (SKSpriteNode *) node;
CGPoint waveScreenPos = [_waveLayer convertPoint:wave.position
toNode:self];
if (waveScreenPos.x <= -wave.size.width) {
wave.position = CGPointMake(wave.position.x+wave.size.width*2,
wave.position.y);
}
}];
}
20 분 동안 유휴 상태 인 iPhone으로 돌아온 이유에 대한 도움이나 통찰력은 게임을 다시로드합니다. 스크롤링 BG 만 누락되었지만 5-15 초 후에 시작되고 정상적으로 보입니다. 다시 말하지만, 처음로드하거나 5 분 동안 종료 한 다음 게임으로 돌아갑니다. 모든 것이 작동하고 즉시로드됩니다.
편집-스크롤하지 않고 BG 이미지를로드하려고 시도했기 때문에 스크롤 기능 / 방법이라는 것을 알고 있으며 20 분 이상 게임을 종료하고 돌아온 후에도 정상적으로로드됩니다. 흠 .. 스크롤링 BG가로드되지 않은 상태에서도 게임을 할 수 있습니다. 스크롤링 BG는 항상 결국로드됩니다 (보통 5-10 초 후에).
확실히 델타 시간입니다.
음, 최고의 임시 / 해결 방법을 찾았습니다.
_dt를 제한하고 있습니다.
if (_dt > 1) {
_dt = currentTime - _lastUpdateTime;
}
_dt가 실제 시나리오에서 1 이상이되어서는 안되기 때문에 이것은 내 목적을 위해 훌륭하게 작동했습니다. 게임이 종료되고 다시 시작될 때 값을 저장하는 더 심층적 인 접근 방식이 있습니다.하지만 이것은 가장 간단한 imo입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다