我正在制作一个 sprite 套件游戏,拥有一个具有平铺纹理的大型 SKSpriteNode 显然比拥有多个具有平铺纹理的 SKSpriteNode 更有效。我的问题是,当我尝试使用
制作 5x5 瓷砖时SKTexture* tex = [SKTexture textureWithRect:CGRectMake(0,0,5,5) inTexture:[SKTexture textureWithImageNamed:@"tile.png"]];
SKSpriteNode* node = [SKSpriteNode spriteNodeWithTexture:tex size:CGSizeMake(100,100)];
图像被适本地调整大小,但它被夹住而不是平铺。在 openGL 术语中,我在需要 GL_REPEAT 的地方得到了 GL_CLAMP_TO_EDGE。无论如何我可以在单个 SKSpriteNode 中实现纹理的平铺效果,而无需创建非常大的图像。
这是我的问题的图片:
最佳答案
Afaik,无法创建具有平铺纹理的 Sprite 。但您可以做的是在一次绘图过程中渲染大量 Sprite 。
来自 Apple 的 documentation (Sprite Kit 最佳实践 -> 绘制内容):
If all of the children of a node use the same blend mode and texture atlas, then Sprite Kit can usually draw these sprites in a single drawing pass. On the other hand, if the children are organized so that the drawing mode changes for each new sprite, then Sprite Kit might perform as one drawing pass per sprite, which is quite inefficient.
关于ios - 如何在 Sprite Kit 中设置要平铺的纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19963513/