iOS Sprite Kit why can't I repeat colorizeWithColor using white color?

后端 未结 2 2001
滥情空心
滥情空心 2021-02-20 13:26

I\'m experimenting with ways of selecting sprite nodes using methods other than scale. The one method that I like the most is colorize with white, which highlights the node visi

2条回答
  •  天涯浪人
    2021-02-20 14:16

    I suggest you make a method to colorize, that returns you SKAction to use, for example:

    -(SKAction*)colorizeChoosenSpriteNodeWithColor:(SKColor*)color
    {
      SKAction *changeColorAction = [SKAction colorizeWithColor:color colorBlendFactor:1.0 duration:0.3];
      SKAction *waitAction = [SKAction waitForDuration:0.2];
      SKAction *startingColorAction = [SKAction colorizeWithColorBlendFactor:0.0 duration:0.3];
      SKAction *selectAction = [SKAction sequence:@[changeColorAction, waitAction, startingColorAction]];
      return selectAction;
    }
    

    And it is important to say if you are using SKSpriteNode that is made from SKColor or from an image. If you are trying to colorize SKSpriteNode that is made like:

    SKSpriteNode *node = [[SKSpriteNode alloc]initWithColor:[SKColor redcolor] size:CGSizeMake(8, 8)];
    

    By running colorize Action you will change that color and with that "startingColorAction" from above you will not make it to the recent color.

    As it says in documentation: "Creates an animation that animates a sprite’s color and blend factor." So by running this Action to a SKSpriteNode that is made just from SKColor it will change the color and running the action with colorblendfactor 0.0 it will do nothing.

    Use this action for colorizing sprite nodes made from images. Try testing it and see what happens.

    And please, please read the "Sprite Kit Programming Guide" first!

提交回复
热议问题