Cocos2d 生成图片分割线

输入父亲节点和宽度偏移值,高度等参数,可以在父节点指定位置生成一个对于默认图片重复展开的分割线

CommonUI.addRopeIntoPanel = function(panel, widthOffset, positionY, ropePngPath){
    ropePngPath = ropePngPath || "res/ui/new_common/n_title_inside.png";
    var panelSize = panel.getContentSize();
    var rope = cc.Sprite.create(ropePngPath);
    rope.setContentSize(cc.size(panelSize.width-widthOffset, 8));
    rope.setPosition(cc.p(panelSize.width/2, positionY));
    rope.setTextureRect(cc.rect(0,0,panelSize.width-widthOffset,8));
    rope.getTexture().setTexParameters(gl.LINEAR,gl.LINEAR,gl.REPEAT,gl.REPEAT);
    panel.addChild(rope, 20);
};

注:输入图片样式时,有可能报错~~~Assert failed: GL_CLAMP_TO_EDGE should be used in NPOT dimensions

按照书面的理解,GL_CLAMP_TO_EDGE should be used in NPOT dimensions指的是CL_CLAMP_TO_EDGE模式不能用非二次幂的图像。那么断言的写法就出现了问题。

原代码:

CCASSERT((_pixelsWide == ccNextPOT(_pixelsWide) || texParams.wrapS == GL_CLAMP_TO_EDGE) &&
    (_pixelsHigh == ccNextPOT(_pixelsHigh) || texParams.wrapT == GL_CLAMP_TO_EDGE),
    "GL_CLAMP_TO_EDGE should be used in NPOT dimensions");

而实际上知道GL_REPEAT等必须使用二次幂,那么这里应该是断言的文本部分内容表述有误。正确的应该是:除了CL_CLAMP_TO_EDGE模式之外,不能使用非二次幂图像。

将图片大小换成长和宽都是二的多少次方的图片即可。

猜你喜欢

转载自blog.csdn.net/zhenyu5211314/article/details/78357171