Background image size / postion iPad

Forums Programming cocos2d support (graphics engine) Background image size / postion iPad

This topic contains 4 replies, has 2 voices, and was last updated by  robodude666 3 years, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
Author Posts
Author Posts
June 26, 2010 at 3:17 pm #222751

elpuerco
Participant
@elpuerco

I have just managed to get my iPad startup application to display a background image, but it is in the wrong position and size?

I use this in my init method:

-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {

CCSprite *bg = [CCSprite spriteWithFile:@"myimage-ipad.png"
rect: CGRectMake(0, 0, 1024, 768)];

bg.position = ccp(0,0);

[self addChild:bg];
}
return self;
}

But what I get is this image in the lower left of the iPad landscape view, as if taking up the lower left quarter of the dispay?

The image is 1024 * 768

Do I need to tell cocos2d something to make it display image in correct size?

Thanks

June 26, 2010 at 3:24 pm #288300

robodude666
@robodude666

You only use the spriteWithFile:rect: method if you want to create a sprite based on a section of an image, such as a sprite sheet. If you want to use the whole image use the regular spriteWithFile method.

Sprites have a default anchor point in the center. If you set the position to 0,0 then the center of the image is at 0,0. To make the image center on the iPad you need to put it at the center of the screen, like this:

CGSize s = [CCDirector sharedDirector].winSize;

[bg setPosition:ccp(s.width/2, s.height/2)];

This will position the image centered in the screen, every time.

June 26, 2010 at 4:11 pm #288301

elpuerco
Participant
@elpuerco

You hero! Thanks. Been bashing my head for ages!

I do notice now tho that the frame rate has dropped to 30 from 60? Is this the norm?

June 26, 2010 at 4:14 pm #288302

elpuerco
Participant
@elpuerco

Ah, sorry that is on simulator, its OK on device.

Thanks so much for helping me ;-)))

June 26, 2010 at 4:20 pm #288303

robodude666
@robodude666

You’re very most welcome. Go make a killer app!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.