Objective c Objective C-CCSprites在我的代码的不同部分进行不同的缩放和显示

Objective c Objective C-CCSprites在我的代码的不同部分进行不同的缩放和显示,objective-c,cocos2d-iphone,ios-simulator,ccsprite,Objective C,Cocos2d Iphone,Ios Simulator,Ccsprite,我正在构建一个应用程序,它有一个主菜单层和一个背景层(用于游戏)。我在两个地方加载完全相同的CCParalax节点代码,使用相同的图像创建无限滚动背景 在游戏性背景层上,背景会相应地显示和滚动。但是,在主菜单层上,背景的缩放很奇怪(它们不会占据整个屏幕),并且也不会进行适当的滚动(可能是因为缩放不正确,所以偏移不起作用) 以下是主菜单上背景的屏幕截图: 这里是背景层(绿线是游戏的一部分): 看起来菜单层正在添加非视网膜显示版本的文件,但如果我将模拟器加载到iPhone(非视网膜)模式,菜单背

我正在构建一个应用程序,它有一个主菜单层和一个背景层(用于游戏)。我在两个地方加载完全相同的CCParalax节点代码,使用相同的图像创建无限滚动背景

在游戏性背景层上,背景会相应地显示和滚动。但是,在主菜单层上,背景的缩放很奇怪(它们不会占据整个屏幕),并且也不会进行适当的滚动(可能是因为缩放不正确,所以偏移不起作用)

以下是主菜单上背景的屏幕截图:

这里是背景层(绿线是游戏的一部分):

看起来菜单层正在添加非视网膜显示版本的文件,但如果我将模拟器加载到iPhone(非视网膜)模式,菜单背景仍然很差:

加载两者的代码几乎相同

以下是主菜单加载程序代码:

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