ios - CCSprites and CCButton in wrong spot in iPad Simulator -
i trying achieve this:
here code:
cgsize size = [uiscreen mainscreen].bounds.size; [self resizesprite:background towidth:size.width toheight:size.height]; nslog(@"screen size: %@",nsstringfromcgsize(size)); background.position = cgpointmake(0 + background.contentsize.width ,size.height - background.contentsize.height); playbutton.position = cgpointmake(size.width/2, size.height/2); nslog(@"button position: %@",nsstringfromcgpoint(playbutton.position)); nslog(@"background position: %@",nsstringfromcgpoint(background.position));
and here resizesprite method:
-(void)resizesprite:(ccsprite*)sprite towidth:(float)width toheight:(float)height { sprite.scalex = width / sprite.contentsize.width; sprite.scaley = height / sprite.contentsize.height; }
when run in iphone 4 inch simulator looks perfect when run on ipad simulator looks this:
if use:
cgsize size = [[ccdirector shareddirector]viewsize];
it looks on ipad:
right solution:
changed
-(void)resizesprite:(ccsprite*)sprite towidth:(float)width toheight:(float)height { sprite.scalex = width / sprite.contentsize.width; sprite.scaley = height / sprite.contentsize.height; }
to:
-(void)resizesprite:(ccsprite*)sprite towidth:(float)width toheight:(float)height { sprite.scalex = width / [sprite boundingbox].size.width; sprite.scaley = height / [sprite boundingbox].size.height; }
and change background position to:
background.position = cgpointmake(size.width/2, size.height/2);
Comments
Post a Comment