Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change a SKSpriteNode Image

i'm new to sprite Kit and having an issue with changing a current SKSpriteNode image.

My spriteNode looks like this

mover = [SKSpriteNode spriteNodeWithTexture:Texture1];
[mover setScale:1.0];
[self addChild:mover];

then i have this method that should change the mover image, but it is not. What am i doing wrong?

- (void)didBeginContact:(SKPhysicsContact *)contact {
    if (contact.bodyA.categoryBitMask == worldCategory) {
        SKTexture* explodeTexture1 = [SKTexture textureWithImageNamed:@"explode"];
        explodeTexture1.filteringMode = SKTextureFilteringNearest;

        mover = [SKSpriteNode spriteNodeWithTexture:explodeTexture1];
    }
}
like image 389
user3423384 Avatar asked Apr 27 '14 18:04

user3423384


2 Answers

You have to change the texture property of your mover object.

Something like this:

mover.texture = [SKTexture textureWithImageNamed:@"explode"];
like image 61
sangony Avatar answered Sep 25 '22 22:09

sangony


This method is actually re-creating the the mover object.

mover = [SKSpriteNode spriteNodeWithTexture:explodeTexture1];

You just need to update the texture with:

mover.texture = explodeTexture1;
like image 40
Callum Boddy Avatar answered Sep 24 '22 22:09

Callum Boddy