gpt4 book ai didi

ios - Spritekit 平行滚动

转载 作者:行者123 更新时间:2023-11-29 10:49:34 25 4
gpt4 key购买 nike

我的游戏中有一个对象的平行滚动问题,我的对象是一条应该重复的线,但我的代码将该线滚动到屏幕外,然后返回到第一个位置并再次滚动:

 - (void)bricksEdgeAnimation {

SKSpriteNode *bEdge = [[SKSpriteNode alloc]initWithImageNamed:@"edge.png"];
bEdge.position = self.view.center;
bEdge.name = @"edge";
[self addChild:bEdge];


}

- (void)moveBg
{
[self enumerateChildNodesWithName:@"edge" usingBlock: ^(SKNode *node, BOOL *stop)
{
SKSpriteNode * bg = (SKSpriteNode *) node;
bg.position = CGPointMake(bg.position.x , bg.position.y - SPEED);

if (bg.position.y <= -bg.size.width)
{
bg.position = CGPointMake(bg.position.x ,
bg.position.y + bg.size.width*2);
}
}];
}

-(void)update:(CFTimeInterval)currentTime {

if (_lastUpdateTime)
{
_dt = currentTime - _lastUpdateTime;
}
else
{
_dt = 0;
}

_lastUpdateTime = currentTime;

[self moveBg];

}

应该是这样的:

enter image description here enter image description here

应该如何更改我的代码以在彼此之后重复这一行?

最佳答案

添加第二个“边缘”节点:

- (void)bricksEdgeAnimation {

SKSpriteNode *bEdge = [[SKSpriteNode alloc]initWithImageNamed:@"edge.png"];
bEdge.position = self.view.center;
bEdge.name = @"edge";
[self addChild:bEdge];

//2nd node - note the name is the same
SKSpriteNode *bEdge1 = [[SKSpriteNode alloc]initWithImageNamed:@"edge.png"];
bEdge1.position = CGPointMake(bEdge.position.x,bEdge.position.y+(bEdge.size.height));
bEdge1.name = @"edge";
[self addChild:bEdge1];
}

//note I changed "width" to "height"
- (void)moveBg
{
[self enumerateChildNodesWithName:@"edge" usingBlock: ^(SKNode *node, BOOL *stop)
{
SKSpriteNode * bg = (SKSpriteNode *) node;
bg.position = CGPointMake(bg.position.x , bg.position.y - SPEED);

if (bg.position.y <= -bg.size.width)
{
bg.position = CGPointMake(bg.position.x ,
bg.position.y + bg.size.height*2);
}
}];
}

关于ios - Spritekit 平行滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21046185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com