大佬教程收集整理的这篇文章主要介绍了[cocos2dx-lua]Cocos2dx-Lua中Sprite精灵的3种创建方法,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
---1.从图片文件创建 --适合于要显示的这张图片的全部区域或部分区域 function TestTest:CreateSprite1() local png = "lobby/lobby.png" --文件路径 local sprite = cc.Sprite:create(png) self:addChild(spritE) local sprite2 = cc.Sprite:create(png,cc.rect(0,100,100)) self:addChild(sprite2) sprite2:setPosition(display.width/2,display.height/2) end ---2.从SpriteFrame对象创建 function TestTest:CreateSprite2() local resPath = "shared/shared_ui.pvr.ccz" local plist = "shared/shared_ui.plist" display.addSpriteFrames(plist,resPath)--载入图像到帧缓存 local spriteFrame = display.newSpriteFrame("shouye_shouye_n.png") local sprite0 = cc.Sprite:createWithSpriteFrame(spriteFramE) sprite0:setPosition(display.width/2,display.height/2+200) self:addChild(sprite0) local sprite = cc.Sprite:createWithSpriteFramename("shouye_shouye_s.png") sprite:setPosition(display.width/2,display.height/2+400) self:addChild(spritE) local fullPath = cc.FileUtils:geTinstance():fullPathForFilename(plist) local Dict = cc.FileUtils:geTinstance():getValueMapFromFile(fullPath) for imgName,v in pairs(Dict.frames) do print(imgName,v) end end ---3.从缓存纹理创建 function TestTest:CreateSprite3() local resPath = "game/game_ui.pvr.ccz" local textureCache = cc.Director:geTinstance():getTextureCache() local pTexture = textureCache:addImage(resPath) --上面两行= local pTexture = display.loadImage(resPath) local sprite = cc.Sprite:createWithTexture(pTexturE) sprite:setPosition(display.width/2+400,display.height/2+400) self:addChild(spritE) end
以上是大佬教程为你收集整理的[cocos2dx-lua]Cocos2dx-Lua中Sprite精灵的3种创建方法全部内容,希望文章能够帮你解决[cocos2dx-lua]Cocos2dx-Lua中Sprite精灵的3种创建方法所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。