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
[About macOS Sequoia] (Updated October 22, 2024)
Live2D Cubism Editor 5.1.02 now supports macOS Sequoia.
Other Live2D Cubism products currently released are not guaranteed to work on macOS Sequoia.
Please refrain from upgrading macOS, as it may not operate properly.

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.