I am making one game in which i am facing problem when I test my App on Device(iPhone4) the background of it is not working. Like when background image ends BLACKISH BACKGROUND COLOR comes. My Background image size is 460X2880,image name "mars_sample.jpg" (for iPhone4) And code for Background Moving is :
-(void)backgroundmoving:(ccTime)dt
{
static float bk_f=0.0f;
bk_f -=0.9;
if (bk_f <= -960*3) {bk_f=0;}
background.position = ccp( 0,bk_f);
}
When I am loading "460X2880" size image as Background image then it doesn't loads in background AND if it is like of size "460X1192" it loads image in background but Showing BLACKISH BACKGROUND Color on Top of screen.
Below one CODE is for Setting Background image :
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
background = [CCSprite spriteWithFile:@"staripad.png"];
background.anchorPoint= ccp(0,0);
[self addChild:background z:0];
} else {
background = [CCSprite spriteWithFile:@"mars_sample.jpg"];
background.anchorPoint= ccp(0,0);
[self addChild:background z:0];
[self schedule:@selector(backgroundmoving:) interval:1/30];
}
Please Give me some suggestions, how it will work. Thanks ALL
Regards,
Tauseef Khan
Check background.position = ccp( 0, bk_f )
in backgroundmoving
you are setting the Y value of the coordinate to a fixed value, bk_f
. I assume that it's the X value that you'd want to change in order to scroll the background image, background.position = ccp( bk_f, 0 )
.
The parameter dt
to backgroundmoving
that I assume is to provide a moving background image is not used.
Make sure that the background view is set to expand to fit it's super view using autosize properties .
Examine the origin in the frame property of your background view - check that it is at the top of your screen.
I'd add a plain UIView behind your background UIImageView and set it's color to green or some other harsh color. That way you could visually confirm the real-estate covered by the views.
//in .h file int bk_f=240;
-(void)backgroundmoving:(ccTime)dt
{
bk_f=bk_f-5;
if(bk_f<=0)
{
background.position = ccp( 240,160);
bk_f=240;
}
else
{
background.position = ccp( bk_f,160);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With