Can't google anything. Actually it is quite few information about this new framework. Only thing I could find is the applying Core Image filter to a texture. But I guess to draw simple rectangle above the image I need to write own CI filter..
Does anybody know something on topic?
If all you need is a rectangle, use @Kex's solution.
In general, you can create a texture from any UIImage or CGImage. [SKTexture textureWithImageNamed:@"Spaceship.png"]
is really just a convenience to [SKTexture textureWithImage:[UIImage imageNamed:@"Spaceship.png"]]
So to do some custom drawing into a texture, you can use, for example:
UIGraphicsBeginImageContext(CGSizeMake(256, 256));
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[SKColor yellowColor] setFill];
CGContextFillEllipseInRect(ctx, CGRectMake(64, 64, 128, 128));
UIImage *textureImage = UIGraphicsGetImageFromCurrentImageContext();
SKTexture *texture = [SKTexture textureWithImage:textureImage];
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithTexture:texture];
[self addChild:sprite];
Textures are just raw graphic representations, I won't solve this with them.
I'd create a sprite from the texture, then a second rectangle sprite with a given size (e.g. 100x100) & I'll add it to the original one at a given position (e.g. CGPointZero
).
SKSpriteNode *rectSprite = [SKSpriteNode spriteNodeWithColor:[SKColor magentaColor] size:CGSizeMake(100, 100)];
rectSprite.position = CGPointZero;
[originalSprite addChild:rectSprite];
That way the the rectangle will be a part of the sprite & all the transformations/actions to the parent sprite (the one with the texture) would apply to it too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With