Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"BackgroundMoving" Code is not Working in iPhone4S

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

like image 451
NSExpression Avatar asked Mar 10 '12 11:03

NSExpression


2 Answers

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.

like image 96
Niels Castle Avatar answered Oct 05 '22 11:10

Niels Castle


//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); 
    }


} 
like image 21
arvind Avatar answered Oct 05 '22 11:10

arvind