lua 对更换精灵图片

来源:互联网 发布:js获取当天24点时间戳 编辑:程序博客网 时间:2024/04/29 23:01

lua中对精灵(sprite)更换图片有两种方式可以使用

一、图片从.plist文件中读取

local topSprite = cc.Sprite.create()if topSprite then   local topPic = nil   if cc.exports.CurrentDisplayAreaType == 0 then                     topPic = 'h_room_banker.png'   else                                                              topPic = 'h_room_robBanker.png'   endlocal spriteFrame = cc.SpriteFrameCache:getInstance():getSpriteFrame(topPic)    if spriteFrame then        topSprite:setSpriteFrame(spriteFrame)    endend

二、直接读取本地路径文件

local topSprite = cc.Sprite.create()local texture = CCTextureCache:sharedTextureCache():addImage('res/../')topSprite:setTexture(texture)
原创粉丝点击