Cocos2d-x adding 3d models to Lua to create 3D animations

Source: Internet
Author: User
Tags addchild

--3d model and creation of 3D animations

Require "cocos2d"

Local Sprite3dscene=class ("Sprite3dscene", function ()

return CC. Scene:create ()

End

--Add Create function

function Sprite3dscene:create ()

Local scene=sprite3dscene.new ()

Scene:addchild (Scene:init ())

Return scene

End

--Adding constructors

function Sprite3dscene:ctor ()

SELF.WINSIZE=CC. Director:getinstance (): Getwinsize ()

End

--Add initialize init () function

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))

--Adding dynamic models

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)

--Create 3D animations

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


The models that are called in the code are copied from the 3D case in cocos2d-x-3.2.


This article is from the computer blog, so be sure to keep this source http://5152481.blog.51cto.com/5142481/1593205

Cocos2d-x adding 3d models to Lua to create 3D animations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.