为什么我的图片不全屏? xcode(精灵套件)

时间:2014-02-12 00:59:47

标签: ios iphone xcode image sprite

-(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;
}

图像未填满整个屏幕。

http://gyazo.com/5dc5e4d7551475f1abac1189ba61bd09

结果有一个gyazo。我认为还有很多其他事情无法解释。

1 个答案:

答案 0 :(得分:0)

这里有一些问题,我很确定它们都出现在这一行:

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

CGSizeMake()有两个论点;宽度和高度按此顺序排列,因此您的代码应如下所示:

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

另外,我不清楚为什么要将两个值除以2。试试这个:

background_2.size = CGSizeMake(screenWidth, screenHeight);