使用情境:
先在Cocos Studio中创建了一个Panel作为背景层,需要在其中平铺图片。
代码如下:
其中注释部分注明了我用过的错误方法,需注意。
local panelPage1 = ccui.Helper:seekWidgetByName(uiNode,"Panel_page1") local panelRepeatBg1 = ccui.Helper:seekWidgetByName(panelPage1,"Panel_repeat_bg") -- 注意1:不要使用plist方式给sprite指定图片,否则getTexture()会得到plist文件的整个图片,而不是你指定的那张小图 -- cc.SpriteFrameCache:getInstance():addSpriteFrames("publish/More/More_png.plist") -- local bgSprite = cc.Sprite:createWithSpriteFrameName("More_repeat_bg.png") local bgSprite = cc.Sprite:create("More/More_repeat_bg.png") bgSprite:setAnchorPoint(0,0) bgSprite:setPosition(0,0) -- 注意2:不能给sprite只设置size,而是要设置rect -- local bgSize = panelRepeatBg1:getContentSize() -- bgSprite:setContentSize(bgSize) local bgRect = panelRepeatBg1:getBoundingBox() bgSprite:setTextureRect(bgRect) bgSprite:getTexture():setTexParameters(gl.LINEAR,gl.LINEAR,gl.REPEAT,gl.REPEAT) panelRepeatBg1:addChild(bgSprite) -- TODO setTexParameters()中4个参数分别什么意思尚待查明
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。