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

ぐ巨炮叔叔 提交于 2019-12-09 15:28:31

问题


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

However, I cannot seem to be able to replicate the colorize with white behavior more than once. Why can't I apply colorizeWithColor using white color more than once?

These two method calls are identical, except for the color used. If I use red, gray, etc, the node responds by flashing for each touch. But If I use white, it does so only once, then never responds to touches again.

[self runAction:[SKAction colorizeWithColor:[SKColor lightGrayColor] colorBlendFactor:0.8 duration:0.6] completion:^{

        [self runAction:[SKAction colorizeWithColorBlendFactor:0.0 duration:0.4]];
    }];

    [self runAction:[SKAction colorizeWithColor:[UIColor colorWithWhite:0.99 alpha:1.0] colorBlendFactor:0.8 duration:0.6] completion:^{

        [self runAction:[SKAction colorizeWithColorBlendFactor:0.0 duration:0.4]];
    }];

回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/20715177/ios-sprite-kit-why-cant-i-repeat-colorizewithcolor-using-white-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!