all. 이제 스프라이트 키트를 사용하여 iOS 게임을 개발 중입니다. 게임 메커니즘에는 다음이 포함됩니다. 스프라이트를 위에서 아래로 무한히 스크롤합니다.SpriteKit : 스프라이트를 무한대로 이동하면 가끔 프레임이 끊어지는 경우가 있습니다.
내 게임 장면은 위쪽, 중간, 아래쪽의 3 개의 스프라이트 만 보유하고 있습니다. 스프라이트 이미지가 수십 개 있습니다. 그래서 내 스프라이트가 3 개의 스프라이트를 생성합니다 (그래서 스프라이트가 전체 화면을 채울 수 있습니다). 하단 스프라이트가 화면을 벗어 났을 때 파괴하고, 최고 스프라이트 이 상단 프레임 아래로 내려갈 때, 새 스프라이트 노드를 만든 다음 아래쪽, 중간, 위쪽 스프라이트를 교환하십시오.
의사 코드
: 인터페이스 파일 : 구현 파일에- GameScene:SKScene
{
...
SKSpriteNode *_topSprite;
SKSpriteNode *_middleSprite;
SKSpriteNode *_bottomSprite;
...
}
:
- (void)update:(CFTimeInterval)currentTime
{
// 1 compute time interval
// 2 update sprite node
_topSprite.position move down 100*timeInterval
_middleSprite.position move down 100*timeInterval
_bottomSprite.position move down 100*timeInterval
// 3 crop the off-screen bottom sprite node
if (_bottomSprite is offScreen)
{
[_bottomSprite removeFromParent]
}
// 4 check the highest sprite position visible
// if the highest position is below the frame top,then create new sprite
_bottomSprite = _middleSprite;
_middleSprite = _topSprite;
_topSprite = [self createNewNode]; // random a sprite image
}
게임의 FPS (60)이며, 노드 수가 증가되지 않습니다. 모두 괜찮은 것 같지만, 때로는 게임이 갑자기 움직이는 프레임이 계속되는 것을 막는 초초 초크가있는 것을 발견했습니다. 본능적으로, 나는 주된 이유가 4 단계에 기인한다고 생각했다. 그러나 나는 그것을 해결할 생각이 없다. 제안 사항을 보내 주시면 감사하겠습니다. 제안
- (SKSpriteNode *)createNewNode {
NSString *blockName = [self randomImageName];
SKSpriteNode *sprite = [[SKSpriteNode alloc] initWithImageNamed:blockName];
sprite.position = _highestPosition;
sprite.anchorPoint = CGPointMake(0.5, 0);
NSLog(@"putAnotherNodeOnTop %@", blockName);
[self addChild:sprite];
return sprite;
}
스프라이트 이미지의 크기는 얼마입니까? 그들은 sprites.atlas에서로드입니까? – Akaino
내 스프라이트 이미지는 모두 같은 크기입니다 : 390 * 512. sprites.atlas를 사용하지 않습니다. – cartmanie
이상한. 그런 문제가 없어야합니다. createNode를 게시 할 수 있습니까? – Akaino