ios – 如何在Sprite Kit中设置纹理到tile

我正在制作一个精灵工具包游戏,与一个具有平铺纹理的大型SKSpriteNode相比,使用具有平铺纹理的多个SKSpriteNode显然更有效.我的问题是当我尝试使用5×5瓷砖时
SKTexture* tex = [SKTexture textureWithRect:CGRectMake(0,5,5) inTexture:[SKTexture textureWithImageNamed:@"tile.png"]];
SKSpriteNode* node = [SKSpriteNode spriteNodeWithTexture:tex size:CGSizeMake(100,100)];

图像的大小适当,但它被夹紧而不是平铺.在openGL术语中,我得到一个GL_CLAMP_TO_EDGE,我想要一个GL_REPEAT.无论如何,我可以在单个SKSpriteNode中实现纹理的平铺效果,而无需创建非常大的图像.

这是我的问题的图像:

解决方法

Afaik,没有办法用平铺纹理创建精灵.但你可以做的是,在一个绘图过程中渲染很多精灵.

来自Apple的documentation(精灵套件最佳实践 – >绘制您的内容):

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 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...