Skip to content

Instantly share code, notes, and snippets.

@oggy83
Created Jul 10, 2021
Embed
What would you like to do?
live2drmmz.js
'use strict';
var _Oggy_Spriteset_Map_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
Spriteset_Map.prototype.createLowerLayer = function() {
_Oggy_Spriteset_Map_createLowerLayer.apply(this);
var live2d = new Sprite_Live2d();
live2d.loadModel("live2d/mark_free_t02/mark_free_t02.model3.json");
live2d.x = 300;
live2d.y = 300;
live2d.scale.set(0.2, 0.2);
this.addChild(live2d);
};
// ----------------------------
// Sprite_Live2d
// ----------------------------
function Sprite_Live2d() {
this.initialize.apply(this, arguments);
};
Sprite_Live2d.prototype = Object.create(PIXI.Container.prototype);
Sprite_Live2d.prototype.constructor = Sprite_Live2d;
Sprite_Live2d.prototype.initialize = function() {
PIXI.Container.call(this);
this._model = null;
};
Sprite_Live2d.prototype.update = function() {
if (this._model) {
this._model.update(16);
}
};
Sprite_Live2d.prototype.loadModel = function(name) {
this.clear();
const option = {autoInteract:false, autoUpdate:false, motionPreload: PIXI.live2d.MotionPreloadStrategy.ALL};
PIXI.live2d.Live2DModel.from('../../' + name, option).then((model)=>{
this._model = model;
this.addChild(model);
model.anchor.set(0.5, 0.5);
}).catch((error) => {
console.error(error);
});
};
Sprite_Live2d.prototype.clear = function() {
if (this._model) {
this.removeChild(this._model);
this._model = null;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment