ios - CCSprites and CCButton in wrong spot in iPad Simulator -


i trying achieve this:

enter image description here

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:

enter image description here

if use:

cgsize size = [[ccdirector shareddirector]viewsize]; 

it looks on ipad:

enter image description here

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

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -