2013-02-18 50 views
0

我的代碼進行連續滾動背景的連續滾動......在cocos2d

NSArray *spaceDusts = [NSArray arrayWithObjects:_spacedust1, _spacedust2, nil]; 
for (CCSprite *spaceDust in spaceDusts) { 
if ([_backgroundNode convertToWorldSpace:spaceDust.position].x < - spaceDust.contentSize.width) { 
    [_backgroundNode incrementOffset:ccp(2*spaceDust.contentSize.width,0) forChild:spaceDust]; 
} 
} 

背景圖像大小爲1024 * 384

當符文到這個模擬器的工作正常,但是當我使用在設備(iphone)
其設置背景到中心,並採取一些加載圖像

由於事先.....

回答

0

我在cocos2d遊戲中的背景滾動代碼:

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
#define MM_BG_SPEED_DUR  (IS_IPAD ? (6.0f) : (2.0f)) 

-(void)onEnter 
{ 
    [super onEnter]; 
    [self initBackground]; 

    [self schedule: @selector(tick:)]; 
} 

-(void)initBackground 
{ 
    NSString *tex = @"BG/Background.png";//[self getThemeBG]; 

    mBG1 = [CCSprite spriteWithFile:tex]; 
    mBG1.position = ccp(s.width*0.5f,s.height*0.5f); 
    [self addChild:mBG1 z:LAYER_BACKGROUND]; 

    mBG2 = [CCSprite spriteWithFile:tex]; 
    mBG2.position = ccp(s.width+s.width*0.5f,s.height*0.5f); 

    mBG2.flipX = true; 
    [self addChild:mBG2 z:LAYER_BACKGROUND]; 

} 


-(void)scrollBackground:(ccTime)dt 
{ 
    CGSize s = [[CCDirector sharedDirector] winSize]; 

    CGPoint pos1 = mBG1.position; 
    CGPoint pos2 = mBG2.position; 

    pos1.x -= MM_BG_SPEED_DUR; 
    pos2.x -= MM_BG_SPEED_DUR; 


    if(pos1.x <=-(s.width*0.5f)) 
    { 
     pos1.x = pos2.x + s.width; 
    } 

    if(pos2.x <=-(s.width*0.5f)) 
    { 
     pos2.x = pos1.x + s.width; 
    } 

    mBG1.position = pos1; 
    mBG2.position = pos2; 

} 

-(void)tick:(ccTime)dt 
{ 
    [self scrollBackground:dt]; 
}