问题描述
Sprite 套件,Xcode.
Sprite Kit, Xcode.
我需要找到一种方法来更改程序本身内的精灵图像.我知道如何创建 jpg 文件并将它们制作成精灵图像...
I need to find a way to change a sprites image within the program itself. I know how to create jpg files and make them into the sprite image...
但是对于这个程序,我需要使用 SKShapeNode 绘制圆/多边形(可能在程序内部发生变化),然后将其传输到 SKSpriteNode 的图像.
But for this program, I need to draw circles/polygons (which may change inside the program) using SKShapeNode, and then transferring this to the SKSpriteNode's image.
假设我已经声明:
SKSpriteNode *sprite;
SKShapeNode *image;
我将如何处理这些变量?
How would I do this with these variables?
谢谢!
当我说图像时,我指的是纹理.
I mean texture when I say image.
推荐答案
如果我正确理解你的问题,你可以在 SKView
上使用 textureFromNode
方法后达到你想要的效果代码>.
If I understand your question correctly, you can achieve what you're after using the textureFromNode
method on SKView
.
在您的 SKScene
中:
-(void)didMoveToView:(SKView *)view {
SKShapeNode *shape = [SKShapeNode shapeNodeWithCircleOfRadius:100];
shape.fillColor = [UIColor blueColor];
shape.position = CGPointMake(self.size.width * 0.25, self.size.height * 0.5);
[self addChild:shape];
SKTexture *shapeTexture = [view textureFromNode:shape];
SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture: shapeTexture];
sprite.position = CGPointMake(self.size.width * 0.75, self.size.height * 0.5);
[self addChild:sprite];
}
希望有帮助!
这篇关于将 SKSprite 的图像更改为 SKShapeNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!