溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

cocos2d-x在Lua中添加3d模型創(chuàng)建3D動(dòng)畫

發(fā)布時(shí)間:2020-07-23 19:03:10 來源:網(wǎng)絡(luò) 閱讀:8057 作者:酷酷小喬 欄目:游戲開發(fā)

--3d模型和3D動(dòng)畫的創(chuàng)建

require"Cocos2d"

local Sprite3DScene=class("Sprite3DScene",function()

   return cc.Scene:create()

end)

--添加create函數(shù)

function Sprite3DScene:create()

   local scene=Sprite3DScene.new()

   scene:addChild(scene:init())

  return scene

end

--添加構(gòu)造函數(shù)

function Sprite3DScene:ctor()

   self.winsize=cc.Director:getInstance():getwinsize()

end

--添加初始化init()函數(shù)

function Sprite3DScene:init()

 local layer=cc.layer:create()

local spobj=cc.Sprite3D:create("boss.obj")

spobj:setTexture("boss.png")

spobj:setScale(10)

layer:addChild(spobj)

spobj:setPosition3D(cc.Vertex3F(self.winsize.width/2,self.winsize.height/2,0))

local a1=cc.RotateBy:create(10,cc.Vertex3F(360,360,360))

local a2=spobj:runAction(cc.RepeatForever:create(a1))

--添加動(dòng)態(tài)模型

local spt=cc.Sprite3D:create("tortoise.c3b")

spt:setScale(0.1)

spt:setPosition3D(cc.Vertex3F(self.winsize.width/2,self.winsize.height/2-80,0))

layer:addChild(spt)

--創(chuàng)建3D動(dòng)畫

local animation=cc.Animation3D:create("tortoise.c3b")

local animate=cc.Animate3D:create(animation,0.4)

spt:runAction(cc.RepeatForever:create(animate))


   return layer

end

return Sprite3DScene


代碼中調(diào)用的這些模型是從cocos2d-x-3.2中3D案例里面復(fù)制過來的。


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI