Cocos Lua creates a replacement picture

Transfer: https://www.cnblogs.com/SkyflyBird/p/7809675.html

About Sprite or ImageView to create pictures or To replace the picture, use cocos 2dx 3.10 lua:

One, sprite related

< p style="color:rgb(0,0,0);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;text-align:left;background-color:rgb(255,255,255); ">— Create from a specified picture

local sprite = cc.Sprite:create("* *.png")

— Create by creating texture cache

local sprite = cc.Sprite:create()local cache = cc.Director:getInstance():getTextureCache():addImage("**.png")sprite:setTexture(cache)

or< /p>

local sprite = cc.Sprite:create()sprite:initWithFile("**.png< span style="color:rgb(128,0,0);line-height:1.5;">")

— Created by .plist, small pictures are produced by TexturePacker to generate texture atlas, This will help reduce the number of file reads, reduce the number of OpenGL ES drawing times, and reduce memory consumption

copy code
local plistName = "**.plist"-- Determine Whether the specified plist file is loadedlocal isLoad = cc.SpriteFrameCache:getInstance():isSpriteFramesWithFileLoaded(plistName)if not isLoad then  -- Load the specified plist file  cc.SpriteFrameCache: getInstance():addSpriteFrames(plistName)end-- Create a sprite based on a picture in the texture atlas< /span>local sprite = cc.Sprite:createWithSpriteFrameName("**.png")< span style="color:rgb(0,128,0);line-height:1.5;">-- According to A picture or frame buffer replacement sprite in the texture atlassprite:setSpriteFrame("***.png< span style="color:rgb(128,0,0);line-height:1.5;">")--local frame = cc.SpriteFrameCache:getInstance():getSpriteFrame("***.png" )sprite:setSpriteFrame(frame)
copy code

One, ImageView related

— Create directly by specifying a picture

local Image = cc.ImageView:create("**.png",ccui.TextureResType.plistType)

The second parameter defaults to: ccui.TextureResType.localType( Or UI_TEX_TYPE_LOCAL)

-- Replace with a pictureImage:loadTexture(< span style="color:rgb(128,0,0);line-height:1.5;">"**.png",ccui.TextureResType.plistType)

< p style="color:rgb(0,0,0);font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;text-align:left;background-color:rgb(255,255,255); ">If there is any improper writing in the above, please leave a message to avoid misleading others, thanks!

Transfer: https://www.cnblogs.com/SkyflyBird/p/7809675.html

About Sprite or ImageView to create pictures or replace pictures, use cocos 2dx 3.10 lua:

One, sprite related< /p>

— Create from a specified picture

local sprite = cc.Sprite:create("**.png")

— Created by creating texture cache

local sprite = cc.Sprite:create()local cache = cc.Director:getInstance():getTextureCache():addImage("**.png" )sprite:setTexture(cache)

or

local sprite = cc.Sprite:create()sprite:initWithFile("**.png")

— Created by .plist, small pictures are produced by TexturePacker to generate texture atlas, which helps to reduce the number of file reads and reduce OpenGL ES Draw times, reduce memory consumption

Copy code
local plistName = "**.plist< span style="color:rgb(128,0,0);line-height:1.5;">"-- Determine whether the specified plist file is loadedlocal isLoad = cc.SpriteFrameCache:getInstance():isSpriteFramesWithFileLoaded(plistName)< /span>if not isLoad then  -- Load the specified plist file  cc.SpriteFrameCache:getInstance():addSpriteFrames(plistName)end-- Create a sprite based on a picture in the texture atlaslocal sprite = cc.Sprite:createWithSpriteFrameName(" span>**.png") -- Replace sprites according to a picture or frame buffer in the texture atlassprite:setSpriteFrame("***.png")--< /span>local frame = cc.SpriteFrameCache:getInstance():getSpriteFrame("***.png ")sprite:setSpriteFrame (frame) 
copy code

One, ImageView related

— Create directly by specifying a picture

local I mage = cc.ImageView:create("**.png",ccui .TextureResType.plistType)

The second parameter defaults to: ccui.TextureResType.localType (or UI_TEX_TYPE_LOCAL)

-- Replace with a pictureImage:loadTexture("**.png",ccui.TextureResType.plistType)

If there is any improper writing in the above, please leave a message to avoid misleading others, thanks!

local  sprite = cc.Sprite:create("**.png")

local sprite = cc.Sprite:create()local cache = cc.Director:getInstance():getTextureCache():addImage( "**.png")sprite:setTexture(cache)

local sprite = cc.Sprite:create()sprite:initWithFile( "**.png")

copy code

< pre style="font-family:'Courier New';">local plistName = **. plist Determine whether the specified plist file is loadedlocal isLoad = cc.SpriteFrameCache:getInstance():isSpriteFramesWithFileLoaded(plistName)if not isLoad then  – – Load the specified plist file  cc .SpriteFrameCache:getInstance():addSpriteFrames(plistName)end According to a picture in the texture atlas Create a spritelocal sprite = cc.Sprite:createWithSpriteFrameName(**.png)< span style="color:rgb(0,128,0); line-height:1.5;">— Replace sprites according to a certain picture or frame buffer in the texture atlas< /span>sprite:setSpriteFrame(“< /span>***.png)local frame = cc.SpriteFrameCache:getInstance():getSpriteFrame( ***.png)sprite:setSpriteFrame(frame)

copy code

copy code

copy code

local Image = cc. ImageView:create("**.png",ccui.TextureResType.plistType )

 -- Replace with a pictureImage:loadTexture("**.png",ccui.TextureResType.plistType)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3642 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.