ios - 如何在 Sprite Kit 中设置要平铺的纹理

标签 ios objective-c sprite-kit

我正在制作一个 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 中实现纹理的平铺效果,而无需创建非常大的图像。

这是我的问题的图片: enter image description here

最佳答案

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/

相关文章:

ios - iCloud 权利被拒绝

ios - 调整 UITableViewCell 大小以适合标签或图像和圆角

swift - SpriteKit 中 "eat"的最佳方法

ios - UITableView 自定义单元格中单元格重用的问题

ios - 从 Google map 到 UITableView 的选取器地点

ios - 将多张图片上传到 Parse 的正确方法

ios - OCMock 抛出 EXC_BAD_ACCESS

objective-c - 检测 Sprite 套件中数组中的对象之间的碰撞

ios - 场景编辑器:如果没有@ 2x,则无法指定纹理名称

ios - 如何创建具有多个图像切换和删除所选图像的 ImageView?