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

后端 未结 2 2024
滥情空心
滥情空心 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:02

    This is very interesting - and I'm not sure I have the answer. Using a white colorisation does to affect a node differently from other colours.

    if you perform a colorize on a sprite node with blueColor and watch in the simulator, the colour will remain.

    [node runAction:[SKAction colorizeWithColor:[SKColor blueColor] colorBlendFactor:0.8 duration:0.6]];
    

    However, if you perform a colorize on a sprite node with whiteColor and watch in the simulator, it appears to automatically unwind (even without any completion block).

    [node runAction:[SKAction colorizeWithColor:[SKColor whiteColor] colorBlendFactor:0.8 duration:0.6]];
    

    I can find no reference to why this might be the case in documentation/header files. Still searching.

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题