视差背景不重复

时间:2014-02-23 15:10:06

标签: ios sprite-kit

我的代码是针对重复移动的背景,它意味着永远重复。但是当我模拟它时,它会变成一次然后背景变成灰色。这是我的代码:

  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];

它有什么问题?

0 个答案:

没有答案