cocos studio 导出的 ExportJson 中包含一个图片精灵。
在程序中想把这个精灵替换成另一张图片时出错。
错误信息:
LUA ERROR: :18: attempt to call method ‘setTexture’ (a nil value)
代码调用
local fishOne = taskbg:getChildByName(“fish_one”)
fishOne:setPosition(150,20)
– fishOne:setTexture(“Shell_1.png”) // 就是这句替换纹理时出错
通过测试后发现 使用 cc.Sprite:create 创建后的精灵 在替换纹理时就不会出错。
local testSprite = cc.Sprite:create(“ball.png”)
testSprite:setPosition(50,20)
taskbg:addChild(testSprite)
testSprite:setTexture(“Shell_1.png”)