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模式之外,不能使用非二次幂图像。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值