I wonder if there is a way to pre-load mtns.
load_motion(motion1.mtn);
...
load_motion(motion2.mtn);
...
load_motion(motion1.mtn);
function load_motion(mtn){
Figure.loadBytes(mtn, function(buf){
motion = new Live2DMotion.loadMotion(buf);
});
}
Very frequently, I load
motion1, then soon
motion2, and soon after
motion1 again.
The above code is making my game run slow on some devices. There isn't a lot of mtns. I need to interchange mtns frequently.
So I want to ask : How do I preload mtns?
PS: I tried to make an array (which would store all the motion bytes), for loop and this:
motion[i] = new Live2DMotion.loadMotion(buf); . But it doesn't work.
Thank you in advance
Comments
Near the very beginning, just after the
.model.jsonis defined into your code:for(var i = 0; i < modelDef.motion.length; i++){ load_motion(modelDef.motion[i], i); }var init_mtn = 0; var curr_mtn = init_mtn; ... function load_motion(mtn, index){ Figure.loadBytes(mtn, function(buf){ motion = new Live2DMotion.loadMotion(buf); motion.setFadeIn(0); motion.setFadeOut(0); motion_bytes[index] = motion; if(index === modelDef.motion.length-1){ startMtn(curr_mtn); } }); }function startMtn(no){ motionMgr.startMotion(motion_bytes[no]); }And in the periodic draw function:if(motionMgr.isFinished()){ motionMgr.startMotion(motion_bytes[curr_mtn]); } motionMgr.updateParam(live2DModel);