0

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?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
4GetFullOf
  • 1,738
  • 4
  • 22
  • 47

1 Answers1

0

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...

T. Benjamin Larsen
  • 6,373
  • 4
  • 22
  • 32
  • Is there a replace SKAction because I can't seem to find a function to help me with that. Can you show me with some code how you would perform a SpriteNode swap when the countdown finishes. Thank you – 4GetFullOf Feb 18 '14 at 21:20
  • No there aren't any built in replaceAction but there is `performSelector:onTarget:` and `customActionWithDuration:actionBlock:` which can be used for basically anything... – T. Benjamin Larsen Feb 19 '14 at 17:15