Display Live2D models on web page.
Actually, it's a simple package for the Live2D official demo.
First, import scripts into your page.
You can download live2d.min.js
from offcial website or get it from the lib
folder.
And include the live2d-helper.min.js
located on the dist
folder.
<script src="live2d.min.js"></script>
<script src="live2d-helper.min.js"></script>
<canvas id="glcanvas" width="400" height="600"></canvas>
<script src="live2d.min.js"></script>
<script src="live2d-helper.min.js"></script>
<script type="text/javascript">
var live2DHelper = new Live2DHelper({canvas: 'glcanvas'});
window.onload = function() {
var path = "name.model.json";
live2DHelper.loadModel(path, function(){
// do something...
});
};
</script>
-
loadModel(modelPath, callback)
modelPath
- path of model json datacallback
- callback
-
releaseModel(no)
no
- model index, default: 0
-
releaseAllModel()
release all model
changeModel(newModelPath, callback)
newModelPath
- new model json data pathcallback
- callback
release the model in bottom of stack,
and the new model will push in top of stack.
! this function is recommended when you have only ctreated one model.
setRandomExpression(no)
no
- model index, default: 0
set random expression
getExpressions(no)
no
- model index, default: 0
return all expression names.
iterate:
for (var name in live2DHelper.getExpressions()) {
// ...
}
setExpression(name, no)
name
- expression nameno
- model index, default: 0
set model expression by name
-
startRandomMotion(no)
no
- model index, default: 0
-
startMotion(namespace, num, no)
namespace
- motion namespacenum
- motion indexno
- model index, default: 0
playSound(path, no)
path
- sound pathno
- model index, default: 0
Play sound.
-
startTurnHead(no)
no
- model index, default: 0
-
stopTurnHead(no)
no
- model index, default: 0
-
followPointer(event)
event
- mouse event
-
viewPointer(x, y)
x
- coordinate xy
- coordinate y
kakinuma4ko / WebLive2DMurakumo
MIT