Giter Site home page Giter Site logo

live2dforcocoscreator's Introduction

Live2d for CocosCreator

根据Lived2d的官方WebGL示例修改,适配 CocosCreator

image

使用方法

  • 将 assest/components 目录中的"live2d"文件夹拷贝到项目中

    image

  • 场景中新建节点并附加组件"Live2dComponent"

    image

    • 设置节点 Size 作为显示 Live2d 模型的画布尺寸,设置 ScaleY 为-1(不知道为什么我设置了 RenderTexture 的 setFlipY(true)也没有用,只能用 Scale 把节点倒置过来)
    • Render Texture: 可以不填,组件会自动创建 cc.RenderTexture 和 cc.Sprite 组件
    • Scale: 显示 Live2d 模型大小(暂时没有找到 live2d 设置缩放的地方,这里直接修改 Viewport 尺寸达到缩放的目的,感觉 3 左右挺好的)
    • Fps: Live2d 的刷新率(游戏 Live2d 在 update 的时候有相当的计算量,所以这里的 fps 可以比游戏的低一些,感觉 30fps 足够了,即使 20fps 也不觉得卡)
    • Loop Idel Motion: 是否自动循环Idel动作
    • Model Name: 加载live2d模型的名字
  • 常用函数

    • this.getComponent(Live2dComponent.live2d //获取Live2d代理对象
    • this.getComponent(Live2dComponent).live2d.getModel(0) //获取Live2d模型
    • this.getComponent(Live2dComponent).live2d.getModel(0).startMotion(动作组名, 动作编号, 切换优先级(大数值打断小数值)) //执行动作
    • 动作结束会在Live2dComponent的节点emit事件Live2dComponent.EvtMotionFinish
    • this.getComponent(Live2dComponent).live2d.getModel(0).setExpression(表情名) //做表情
    • this.getComponent(Live2dComponent).live2d.loadModel(模型名) //加载模型,现在一次只有一个模型

注意事项

  • 资源默认放置在 resources\live2d 文件夹中
  • 由于CocosCreator的资源加载策略,自动识别资源类型与扩展名所以需要将live2d导出的资源重命名
    • XXX.moc3 => XXX_moc3.bin
    • XXX.model3.json => XXX_model3.bin
    • XXX.physics3.json => XXX_physics3.bin
    • XXX.pose3.json => XXX_pose3.bin
    • XXX.userdata3.json => XXX_userdata3.bin
    • XXX.motion3.json => XXX_motion3.bin
    • 使用脚本resource/rename_live2d.py可自动转换resource/live2d目录下的文件名

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.