--3d模型和3D动画的创建
require"Cocos2d"
local Sprite3DScene=class("Sprite3DScene",function()
return cc.Scene:create()
end)
--添加create函数
function Sprite3DScene:create()
local scene=Sprite3DScene.new()
scene:addChild(scene:init())
return scene
end
--添加构造函数
function Sprite3DScene:ctor()
self.winsize=cc.Director:getInstance():getwinsize()
end
--添加初始化init()函数
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))
--添加动态模型
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)
--创建3D动画
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
代码中调用的这些模型是从cocos2d-x-3.2中3D案例里面复制过来的。