cocos2d中重复背景有黑边!
我正在尝试为我的 iPhone 应用程序设置平铺/重复背景。
代码“有效”,因为背景按应有的方式重复,但每次重复周围似乎都有黑色边框,我不知道为什么,图像恰好是 200x200。下面是它的外观和代码的屏幕截图:
if ((self=[super init])) {
CCSprite * bg = [CCSprite spriteWithFile:@"pattern11.jpg" rect:CGRectMake(0, 0, 1000, 520)];
[bg setPosition:ccp(0, 0)];
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[bg.texture setTexParameters:¶ms];
[self addChild:bg z:0];
}
I am attempting to setup a tiled/repeating background for my iPhone app.
The code "works" in that the background is repeating like it should be but I seem to have a black border around each repetition and I dont know why, the image is exactly 200x200. Here is a screenshot of how it looks along with the code:
if ((self=[super init])) {
CCSprite * bg = [CCSprite spriteWithFile:@"pattern11.jpg" rect:CGRectMake(0, 0, 1000, 520)];
[bg setPosition:ccp(0, 0)];
ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
[bg.texture setTexParameters:¶ms];
[self addChild:bg z:0];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
纹理应该始终是 2 的幂...例如 16,32,64,128,256,512,1024。
尝试将图像大小调整为 256x256 或 128x128。
Textures should always be in power of two... like 16,32,64,128,256,512,1024.
Try resizing the image to 256x256 or 128x128.
我还遇到过这个相当常见的问题,即无法在 Cocos2d-iPhone 中平铺任意大小的纹理,因此我组合了一个简单的 TiledSprite 类来平铺/剪辑纹理或子纹理到任何宽度/高度。
直接跳转到这里的源代码(随意使用):
https://gist.github.com/Nolithius/ 6694990
或者查看这篇简短文章中的使用示例、屏幕截图和评论:
http://www.nolithius.com/game-development/cocos2d-iphone-repeating -精灵
祝你好运!
I've also ran across this rather common problem with not being able to tile arbitrarily-sized textures in Cocos2d-iPhone, so I put together a simple TiledSprite class to tile/clip a texture or subtexture to any width/height.
Jump right to the source code here (use at will):
https://gist.github.com/Nolithius/6694990
Or have a look at a usage sample, screenshot, and commentary in this brief article:
http://www.nolithius.com/game-development/cocos2d-iphone-repeating-sprite
Best of luck!