Repeating background in cocos2d has black edges!

孤者浪人 提交于 2019-12-30 05:04:06

问题


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:&params];
    [self addChild:bg z:0];
}


回答1:


Textures should always be in power of two... like 16,32,64,128,256,512,1024.

Try resizing the image to 256x256 or 128x128.




回答2:


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!



来源:https://stackoverflow.com/questions/6736759/repeating-background-in-cocos2d-has-black-edges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!