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.
我正在尝试使用除scale之外的方法来选择sprite节点的方法。我最喜欢的一种方法是用白色着色,这可以明显地突出显示节点。
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?
但是,我似乎无法多次用白色行为复制着色。为什么我不能多次使用白色应用colorizeWithColor?
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]];
}];
2 个解决方案
#1
6
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.
如果使用blueColor在精灵节点上执行着色并在模拟器中观察,颜色将保留。
[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).
但是,如果使用whiteColor在sprite节点上执行着色并在模拟器中观察,它似乎会自动展开(即使没有任何完成块)。
[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
2
I suggest you make a method to colorize, that returns you SKAction to use, for example:
我建议你制作一个着色的方法,它会让你使用SKAction,例如:
-(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:
如果您使用的是由SKColor或图像制作的SKSpriteNode,则很重要。如果您正在尝试着色SKSpriteNode,其形状如下:
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.
通过运行colorize Action,您将更改该颜色,并从上方使用“startingColorAction”,您将无法使其成为最近的颜色。
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.
正如它在文档中所说:“创建一个动画,动画精灵的颜色和混合因子。”因此,通过将此Action运行到仅由SKColor创建的SKSpriteNode,它将更改颜色并使用colorblendfactor 0.0运行操作,它将不执行任何操作。
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!
请先阅读“精灵套件编程指南”!
#1
6
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.
如果使用blueColor在精灵节点上执行着色并在模拟器中观察,颜色将保留。
[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).
但是,如果使用whiteColor在sprite节点上执行着色并在模拟器中观察,它似乎会自动展开(即使没有任何完成块)。
[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
2
I suggest you make a method to colorize, that returns you SKAction to use, for example:
我建议你制作一个着色的方法,它会让你使用SKAction,例如:
-(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:
如果您使用的是由SKColor或图像制作的SKSpriteNode,则很重要。如果您正在尝试着色SKSpriteNode,其形状如下:
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.
通过运行colorize Action,您将更改该颜色,并从上方使用“startingColorAction”,您将无法使其成为最近的颜色。
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.
正如它在文档中所说:“创建一个动画,动画精灵的颜色和混合因子。”因此,通过将此Action运行到仅由SKColor创建的SKSpriteNode,它将更改颜色并使用colorblendfactor 0.0运行操作,它将不执行任何操作。
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!
请先阅读“精灵套件编程指南”!