SKSpriteNode with the image will not be painted

I created SKSpriteNode like this:

 //Easy Button Image

_easyImage = [[SKSpriteNode alloc]initWithImageNamed:@"smiley.png"];
_easyImage.position = CGPointMake(-20,screenHeight / 2);
_easyImage.name = easyBtnName;
_easyImage.physicsBody.affectedByGravity = NO;
_easyImage.zPosition = 10;

[self addChild:_easyImage];

I am trying to colorize the image after clicking in the method that I started using. I have a reference to the SKSpriteNode property, so when I see that it clicked, I execute this code

        SKAction *pulseRed = [self colorizeChoosenSpriteNodeWithColor:[SKColor redColor]];
        [_easyImage runAction: pulseRed];

What is the link to this method

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

However, the color of my image never changes. I can completely change the texture of the image, but I cannot just change the coloring.

EDIT: I removed the code distracting from the problem. I debugged the code and it definitely works correctly, but I am not getting the expected result.

Update: A color appears under my image that I discovered.

Same code except one has a missing image.  Red color shows on the Sprite Node with the missing image?

, . , . spriteNode?

+4
2

, for . :

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     for (UITouch *touch in touches) {   
     if ([node.name isEqualToString:easyBtnName]){
         _easyImage.color = [SKColor redColor];
         _easyImage.colorBlendFactor = 1;
         SKAction *pulseRed = [self colorizeChoosenSpriteNodeWithColor:[SKColor redColor]];
    [_easyImage runAction: pulseRed];
    } }
    }
+1

,

func changeColor() -> UIColor{
  var color:UIColor
  switch (arc4random_uniform(6)) {
    case 0:
      color = UIColor.purpleColor()
    case 1:
      color = UIColor.blueColor()
    case 2:
      color = UIColor.yellowColor()
    case 3:
      color = UIColor.magentaColor()
    case 4:
      color = UIColor.greenColor()
    default:
      color = UIColor.redColor()
  }
  return color
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) 
{
  let colorAction = SKAction.colorizeWithColor(self.changeColor(), colorBlendFactor: 1, duration: 1)
  SKSpriteNode.runAction(colorAction)
}

. !

0

Source: https://habr.com/ru/post/1529360/


All Articles