Cocos3dx入门

Quick+Cocos3dx+lua版本,资源见附件

local M = class("MainGame")

local camera = nil
function M:ctor()

    --创建主场景
    local mainScene = display.newScene("MainScene")
    --创建3D环境
    --3Dlayer必须放在Layer上
    local sceneLayer = cc.Layer:create()
    mainScene:addChild(sceneLayer)   
    --创建3DLayer
    local layer3D = cc3.C3DLayer:create()
    --创建相机
    camera = cc3.C3DCamera:createOrthographic(layer3D:getWidth(), layer3D:getHeight(), 1, -1000, 1000)
    --相机加入3D layer
    layer3D:get3DScene():addChild(camera)
    layer3D:get3DScene():setActiveCamera(0)
    sceneLayer:addChild(layer3D)
    mainScene.layer3D = layer3D
    
    --加载人物模型
    local name,url = "lz","test/lzzl/lz.ckb"
    local role = cc3.C3DSprite:create(name)
    role:loadFromFile(url, true)
    --参数依次为:名称,开始帧,结束帧,重复次数,播放速度
    role:addAnimationClip(name, 0, role:getAnimationFrameCount(), 0, 1.0)
    role:playAnimationClip(name)
    role:setScale(200)
    layer3D:get3DScene():addChild(role)
    
    --显示场景
    display.replaceScene(mainScene)
end

return M

你可能感兴趣的:(OS)