Thursday, 15 August 2013

iphone - Continuous Scrolling of background in cocos2d -



iphone - Continuous Scrolling of background in cocos2d -

my code continuous scrolling ......

nsarray *spacedusts = [nsarray arraywithobjects:_spacedust1, _spacedust2, nil]; (ccsprite *spacedust in spacedusts) { if ([_backgroundnode converttoworldspace:spacedust.position].x < - spacedust.contentsize.width) { [_backgroundnode incrementoffset:ccp(2*spacedust.contentsize.width,0) forchild:spacedust]; } }

background image size 1024*384

when rune simulator work when utilize in device(iphone) set background center , take load image

thanks in advance.....

my code background scroll in cocos2d game:

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

iphone ios cocos2d-iphone scroll

No comments:

Post a Comment