2014-02-12 76 views
0
-(void)AnimateBackground 
{ 
//set our background animation 
SKAction *Fadein = [SKAction fadeInWithDuration: 2]; 
SKAction *Fadeout = [SKAction fadeOutWithDuration:1.25]; 

SKAction *wait2 = [SKAction waitForDuration: 2]; 
SKAction *wait4 = [SKAction waitForDuration:4]; 

SKSpriteNode *background_2 = [SKSpriteNode spriteNodeWithImageNamed:@"background2"]; 

SKAction *sequence2 = [SKAction sequence:@[wait4, Fadein, wait2,Fadeout]]; 

background_2.position = CGPointMake(screenWidth/2, screenHeight/2); 
background_2.alpha = 0; 
background_2.size = CGSizeMake((float)screenHeight/2, (float)screenWidth/2); 


[self addChild:background_2]; 
[background_2 runAction:sequence2]; 
} 

-(id)initWithSize:(CGSize)size { 
if (self = [super initWithSize:size]) { 
    /* Setup your scene here */ 

    //init several sizes used in all scene 
    screenRect = [[UIScreen mainScreen] bounds]; 
    screenHeight = screenRect.size.height; 
    screenWidth = screenRect.size.width; 


    [self AnimateBackground]; 


} 
return self; 
} 

圖像沒有填滿整個屏幕。爲什麼我的圖像不是全屏? xcode(sprite kit)

http://gyazo.com/5dc5e4d7551475f1abac1189ba61bd09

有結果的gyazo。我認爲沒有其他解釋。

回答

0

你有幾個問題在這裏,我敢肯定,他們都發生在這條線:

background_2.size = CGSizeMake((float)screenHeight/2, (float)screenWidth/2); 

CGSizeMake()有兩個參數;寬度和順序的高度,使你的代碼應該是這樣的:

background_2.size = CGSizeMake((float)screenWidth/2, (float)screenHeight/2); 

而且,我不明白爲什麼要除以二兩個值。試試這個:

background_2.size = CGSizeMake(screenWidth, screenHeight); 
相關問題