Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

If you have any questions, reports, suggestions, or requests about Live2D, please send them to this forum.
※We cannot guarantee statements or answers from Live2D staff. Thank you for your understanding in advance.
 
Live2D Cubism
Cubism Products and Downloads
Cubism product manuals and tutorials
Cubism Editor Manual    Cubism Editor Tutorial    Cubism SDK Manual    Cubism SDK Tutorial
[INFORMATION](03/28/2024)
Cubism Editor 5.1 alpha version is now available!
Find out how to use the new features here.
Please take this opportunity to use it and give us your feedback!

For more information and download, please check out the Cubism Editor 5.1 alpha category.

Question - preloading motions

RusRus
edited February 2016 in Help
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

  • Actually my pre-loading method using arrays suddenly worked. I must have made a trivial mistake in my code somewhere. Thank you anyways
  • And for anyone who want's to know how I did mtn preloading, here's how:

    Near the very beginning, just after the .model.json is 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);
    
  • I see. Thank you for sharing the information .
Sign In or Register to comment.