【发布时间】:2014-10-03 05:37:47
【问题描述】:
我设置了背景,它正在水平滚动,这是我的代码:
-(void)initalizingScrollingBackground
{
for (int i = 0; i < 2; i++)
{
SKSpriteNode *bg = [SKSpriteNode spriteNodeWithImageNamed:@"background"];
bottomScrollerHeight = bg.size.height;
bg.position = CGPointMake(i * bg.size.width, 0);
bg.anchorPoint = CGPointZero;
bg.name = @"background";
[self addChild:bg];
}
}
还有这段代码:
- (void)moveBottomScroller
{
[self enumerateChildNodesWithName:@"background" usingBlock: ^(SKNode *node, BOOL *stop)
{
SKSpriteNode * bg = (SKSpriteNode *) node;
CGPoint bgVelocity = CGPointMake(-BG_VELOCITY, 0);
CGPoint amtToMove = CGPointMultiplyScalar(bgVelocity,_dt);
bg.position = CGPointAdd(bg.position, amtToMove);
//Checks if bg node is completely scrolled off the screen, if yes then put it at the end of the other node
if (bg.position.x <= -bg.size.width)
{
bg.position = CGPointMake(bg.position.x + bg.size.width*2,
bg.position.y);
}
[bg removeFromParent];
[self addChild:bg]; //Ordering is not possible. so this is a hack
}];
}
第二部分使背景滚动。没有它,背景仍然存在。
另外,如果没有 movebottomscroller,我的精灵会出现在背景之上。使用 movebottomscroller,他出现在滚动背景后面。有什么命令可以将他带到前线,高于任何其他背景?
谢谢!
【问题讨论】:
标签: ios ios7 sprite-kit