本文介绍了使用图案图像填充SKShapeNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用图像/模式填充SKShapeNode,但我仍然没有成功。



你能帮我解决这个问题还是给我一个替代方案? 我想创建一个填充图案图像的可碰撞自定义形状(来自任何SpriteKit类型)。



我尝试过以下方法:

  UIBezierPath * path = [[UIBezierPath alloc] init]; 
[path addArcWithCenter:CGPointMake(0.0,0.0)radius:50.0 startAngle:0.0 endAngle:(M_PI * 2.0)顺时针:是];
SKShapeNode * shape = [[SKShapeNode alloc] init];
UIImage * patternImg = [UIImage imageNamed:@pattern];
shape.path = path.CGPath;
shape.fillColor = [[SKColor alloc] initWithCGColor:[[UIColor alloc] initWithPatternImage:patternImg] .CGColor];

以及:

  shape.fillColor = [[SKColor alloc] initWithPatternImage:[[UIImage alloc] initWithCGImage:[UIImage imageNamed:@Basketball]。CGImage]]; 

这是有效的(但它不是我想要的):

  shape.fillColor = [SKColor redColor]; 

谢谢!

解决方案

我在游戏中遇到了样本问题,最后我的解决方案是添加一个SKSpriteNode作为SKShapeNode的子项,它运行正常。

  SKSpriteNode * node = [[SKSpriteNode alloc] initWithImageNamed:@bombIcon.png]; 
node.name = @炸弹;
node.size = CGSizeMake(10,10);
[self.bombNode addChild:node];

其中self.bombNode是SKShapeNode。




I'm trying to fill a SKShapeNode with an Image/pattern but I'm still unsuccessfull.

Can you help me solving this or giving me an alternative? I want to create a collidable custom shape (from any SpriteKit kind) filled with a pattern image.

I've tried the following:

UIBezierPath *path = [[UIBezierPath alloc] init];
    [path addArcWithCenter:CGPointMake(0.0, 0.0) radius:50.0 startAngle:0.0 endAngle:(M_PI*2.0) clockwise:YES];
SKShapeNode *shape = [[SKShapeNode alloc] init];
UIImage *patternImg = [UIImage imageNamed:@"pattern"];
shape.path = path.CGPath;
shape.fillColor = [[SKColor alloc] initWithCGColor:[[UIColor alloc] initWithPatternImage:patternImg].CGColor];

and also:

shape.fillColor = [[SKColor alloc] initWithPatternImage:[[UIImage alloc] initWithCGImage:[UIImage imageNamed:@"Basketball"].CGImage]];

This works (but it isn't what I'm looking for):

shape.fillColor =  [SKColor redColor];

Thank you!

解决方案

i had the sample problem in my game, finally my solution was to add a SKSpriteNode as a child of the SKShapeNode and it worked fine.

SKSpriteNode* node = [[SKSpriteNode alloc] initWithImageNamed:@"bombIcon.png"];
node.name = @"bomb";
node.size = CGSizeMake(10, 10);
[self.bombNode addChild:node];

Where self.bombNode is a SKShapeNode.

Hope it helps

这篇关于使用图案图像填充SKShapeNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 20:01