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

前端之家收集整理的这篇文章主要介绍了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.

原文链接:https://www.f2er.com/iOS/332068.html

猜你在找的iOS相关文章