1
votes

I applied a mask to SKCropNode And I see what i need now but the cropped node has the size of the full image i just want to access the cropped part not the full image can i get that into SKSpriteNode??

Here is my code

SKSpriteNode *pic = [SKSpriteNode spriteNodeWithImageNamed:@"test.png"];
pic.name = @"PictureNode";
SKSpriteNode *mask = [SKSpriteNode spriteNodeWithImageNamed:@"2.png"];
mask.size=CGSizeMake(50, 50);
mask.position=CGPointMake(0, 50);
SKCropNode *cropNode = [SKCropNode node];
cropNode.position=CGPointMake(160, 70);
[cropNode addChild:pic];
[cropNode setMaskNode:mask];
[self addChild:cropNode];

and here are the images and result :

mask Image

image

result

Thanks in advance

1
Can you please show the result and the source images?Andrey Gordeev
The result seems fine... What do you want to achieve?Andrey Gordeev
i want to detect the press on the cropped area only...if i press in any point in the hidden image area it says that i pressed on the cropNodeMoataz Hossam
This question is very different that you asked above. Please add a code which you use to handle gesturesAndrey Gordeev

1 Answers

2
votes

As far as I understood, you are trying to get cropped part as a SKSpriteNode, if it is the case, you can manage it as follows:

    SKTexture *oldWholeTexture = [self.scene.view textureFromNode:cropNode];
    SKTexture *newTexture = [SKTexture textureWithRect:CGRectMake(140.f/364.f,56.f/365.f,80.f/364.f,125.f/365.f) inTexture: oldWholeTexture];
    SKSpriteNode *newNode = [SKSpriteNode spriteNodeWithTexture:newTexture];

CGRect parameter of textureWithRect takes unit values, so I normalized my values according my texture size. Bottom left is (0,0).