2014-02-14 167 views
0

如何设置SKTexture的尺寸Ive通过文档Class Reference我没有看到能够设置尺寸的任何内容。我知道尺寸方法是一种返回方法,但只是为了清楚我在下面的代码中想要做什么。SKTexture的设置尺寸

_bomb = [SKSpriteNode spriteNodeWithImageNamed:@"Bomb5.gif"]; 

    SKTexture *Bomb5 = [SKTexture textureWithImageNamed:@"Bomb5.gif"]; 
    Bomb5.size = CGSizeMake(40, 40); 

    SKTexture *Bomb4 = [SKTexture textureWithImageNamed:@"Bomb4.gif"]; 
    Bomb4.size = CGSizeMake(40, 40); 

    SKTexture *Bomb3 = [SKTexture textureWithImageNamed:@"Bomb3.gif"]; 
    Bomb3.size = CGSizeMake(40, 40); 

    SKTexture *Bomb2 = [SKTexture textureWithImageNamed:@"Bomb2.gif"]; 
    Bomb2.size = CGSizeMake(40, 40); 

    SKTexture *Bomb1 = [SKTexture textureWithImageNamed:@"Bomb1.gif"]; 
    Bomb1.size = CGSizeMake(40, 40); 

    SKTexture *explostion = [SKTexture textureWithImageNamed:@"explosionnn.gif"]; 
    explostion.size = CGSizeMake(90, 90); 
    //5 second countdown and the bomb explodes 
    countdown = [SKAction animateWithTextures:@[Bomb5,Bomb4, Bomb3, Bomb2, Bomb1, explostion] timePerFrame:1]; 

另一种解决方案?:也许我可以在序列添加动作,其中5秒倒计时后,而不是当它到达最后一个动漫形象,我可以改变spriteNode的大小。但是,如果我这样做,我如何从炸弹所在的中心位置改变图像的大小?

回答

0

你是对:不能改变纹理的大小,作为纹理基本上图像:“一个SKTexture对象是可以被应用于由SKEmitterNode对象创建SKSpriteNode物体或颗粒的图像。” (来自documentation)。

你有没有考虑过爆炸的独立精灵?然后,当倒计数达到零时,您可以简单地用倒数替代倒计时精灵。如果你让一个工厂级来创建你的精灵,这将为你节省很多麻烦,如果你想在你的游戏的其他地方使用同样的爆炸......

+0

是否有替代SKAction,因为我似乎无法找到一个功能来帮助我。你可以告诉我一些代码,当倒数结束时你将如何执行SpriteNode交换。谢谢 – 4GetFullOf

+0

不,没有任何内置的replaceAction,但有'performSelector:onTarget:'和'customActionWithDuration:actionBlock:'这可以用于基本上任何事情...... –