1

メイン メニュー レイヤーと背景レイヤー (ゲームプレイ用) を持つアプリを構築しています。同じ画像を使用して無限スクロールの背景を作成し、両方の場所でまったく同じ CCParallax ノード コードを読み込んでいます。

ゲームプレイの背景レイヤーでは、背景が適切に表示およびスクロールされます。ただし、メイン メニュー レイヤーでは、背景が奇妙にスケーリングされ (画面全体を占有しない)、適切にスクロールされません (おそらく、何らかの理由でスケールがオフになっているため、オフセットが機能していないため)。

これは、メイン メニューの背景がどのように見えるかのスクリーンショットです。 メインメニューの背景

これは背景レイヤーにあります (緑の線はゲームプレイの一部です)。 ゲームプレイの背景

メニュー レイヤーが非 Retina ディスプレイ バージョンのファイルを追加しているように見えますが、シミュレーターを iPhone (非 Retina) モードにロードすると、多くの背景がまだオフになっています。

非網膜メニューの背景

2 つをロードするコードはほとんど同じです。

メイン メニュー ローダーのコードは次のとおりです。

-(id)init {
    self = [super init];
    if (self != nil) {
        CGSize winSize = [CCDirector sharedDirector].winSize;

        _backgroundNode = [CCParallaxNode node];
        [self addChild:_backgroundNode z:-1];

        _backgroundGrid1 = [CCSprite spriteWithFile:@"grid.png"];
        _backgroundCircuits1 = [CCSprite spriteWithFile:@"bg-circuits.png"];

        _backgroundGrid1.anchorPoint = CGPointMake(0,0);
        _backgroundCircuits1.anchorPoint = CGPointMake(0,0);
        CGPoint gridSpeed = ccp(0.05, 0.05);
        CGPoint circuitSpeed = ccp(0.1, 0.1);

        [_backgroundNode addChild:_backgroundGrid1 z:1 parallaxRatio:gridSpeed positionOffset:ccp(0,-winSize.height)];
        [_backgroundNode addChild:_backgroundCircuits1 z:0 parallaxRatio:circuitSpeed positionOffset:ccp(0,-winSize.height)];

        [self scheduleUpdate];
    }
    return self;
}

- (void)update:(ccTime)dt {

    CGPoint backgroundScrollVel = ccp(0, 1000);
    _backgroundNode.position = ccpAdd(_backgroundNode.position, ccpMult(backgroundScrollVel, dt));

    NSArray *backgroundGrids = [NSArray arrayWithObjects:_backgroundGrid1, nil];
    for (CCSprite *b in backgroundGrids) {
        if ([_backgroundNode convertToWorldSpace:b.position].y > 0) {
            [_backgroundNode incrementOffset:ccp(0,-(b.contentSize.height/3)) forChild:b];
        }
    }

    NSArray *backgroundCircuits = [NSArray arrayWithObjects:_backgroundCircuits1, nil];
    for (CCSprite *bc in backgroundCircuits) {
        if ([_backgroundNode convertToWorldSpace:bc.position].y > 0) {
            [_backgroundNode incrementOffset:ccp(0,-(bc.contentSize.height/3)) forChild:bc];
        }
    } 
}

背景レイヤーのコードは次のとおりです。

- (id)init
{
    self = [super init];
    if (self != nil) {
        CGSize winSize = [CCDirector sharedDirector].winSize;

        _backgroundNode = [CCParallaxNode node];
        [self addChild:_backgroundNode z:-1];

        _backgroundGrid1 = [CCSprite spriteWithFile:@"grid.png"];
        _backgroundCircuits1 = [CCSprite spriteWithFile:@"bg-circuits.png"];
        _backgroundGrid1.anchorPoint = CGPointMake(0,0);
        _backgroundCircuits1.anchorPoint = CGPointMake(0,0);
        CGPoint gridSpeed = ccp(0.05, 0.05);
        CGPoint circuitSpeed = ccp(0.1, 0.1);

        [_backgroundNode addChild:_backgroundGrid1 z:1 parallaxRatio:gridSpeed positionOffset:ccp(0,-winSize.height)];
        [_backgroundNode addChild:_backgroundCircuits1 z:0 parallaxRatio:circuitSpeed positionOffset:ccp(0,-winSize.height)];

    [self scheduleUpdate];

    return self;
}

- (void)update:(ccTime)dt {

    CGPoint backgroundScrollVel = ccp(0, 1000);
    _backgroundNode.position = ccpAdd(_backgroundNode.position, ccpMult(backgroundScrollVel, dt));

    NSArray *backgroundGrids = [NSArray arrayWithObjects:_backgroundGrid1, nil];
    for (CCSprite *b in backgroundGrids) {
        if ([_backgroundNode convertToWorldSpace:b.position].y > 0) {
            [_backgroundNode incrementOffset:ccp(0,-(b.contentSize.height/3)) forChild:b];
        }
    }

    NSArray *backgroundCircuits = [NSArray arrayWithObjects:_backgroundCircuits1, nil];
    for (CCSprite *bc in backgroundCircuits) {
        if ([_backgroundNode convertToWorldSpace:bc.position].y > 0) {
            [_backgroundNode incrementOffset:ccp(0,-(bc.contentSize.height/3)) forChild:bc];
        }
    } 
}
4

0 に答える 0