废话不多说,直接上代码
--lua --获取场景 local scene= CCDirector:sharedDirector():getRunningScene() --创建精灵 local testSp = CCSprite:create() testSp:setPosition(ccp(250,250)) scene:addChild(testSp,200) --更换图片 local texture = CCTextureCache:sharedTextureCache():addImage("icon/100001.png") texture:retain() testSp:setTexture(texture) --这里一定要设置好大小 local s = texture:getContentSize() testSp:setTextureRect(CCRectMake(0,0,s.width,s.height))