cocos2d中重复背景有黑边!

发布于 2024-11-25 09:52:29 字数 516 浏览 0 评论 0原文

我正在尝试为我的 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:&params];
    [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];
}

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

水染的天色ゝ 2024-12-02 09:52:29

纹理应该始终是 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.

落叶缤纷 2024-12-02 09:52:29

我还遇到过这个相当常见的问题,即无法在 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文