Parallax background does not repeat

别来无恙 提交于 2019-12-11 18:14:15

问题


My code is for a repeating moving background, and it's meant to repeat forever. But when I simulate it, it goes once and then the background just goes grey. This is my code:

  SKTexture* bgTexture = [SKTexture textureWithImageNamed:@"nightbackground"];
    bgTexture.filteringMode = SKTextureFilteringNearest;

    SKAction* movebgSprite = [SKAction moveByX:-bgTexture.size.width*2 y:0 duration:0.1 * bgTexture.size.width*2];
    SKAction* resetbgSprite = [SKAction moveByX:bgTexture.size.width*2 y:0 duration:0];
    SKAction* movebgSpritesForever = [SKAction repeatActionForever:[SKAction sequence:@[movebgSprite, resetbgSprite]]];

    for( int i = 0; i < 2 + self.frame.size.width / ( bgTexture.size.width * 2 ); ++i ) {
        SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:bgTexture];
        [sprite setScale:1.0];
        sprite.zPosition = -20;
        sprite.position = CGPointMake(self.size.width/2, self.size.height/2);
        [sprite runAction:movebgSpritesForever];
        [self addChild:sprite];

What might be wrong with it?

来源:https://stackoverflow.com/questions/21969989/parallax-background-does-not-repeat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!