How do I set a size for a SKTexture Ive gone through the documentation Class Reference I don't see anything about being able to set the size. I know the size method is a return method but just to make it clear what I'm trying to do its in my code below.

    _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];

Another solution?: Maybe I could add actions in sequence where after the 5 second countdown I can change the size of the spriteNode instead when it reaches the last animation image. But if I were to do it this way how do I change the size of the image from the centre origin of where the bomb is?

有帮助吗?

解决方案

You are right: You cannot change the size of the texture, as the texture essentially is the image: "An SKTexture object is an image that can be applied to SKSpriteNode objects or particles created by a SKEmitterNode object." (from the documentation).

Have you considered having a separate sprite for the explosion? Then you can simply replace the countdown-sprite with this when the countdown has reached zero. If you put a factory-class to create your sprites this will also save you a lot of hassle if you want to use the same explosion elsewhere in your game...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top