Created
July 10, 2021 13:43
-
-
Save oggy83/ff41642e83cc0b9fb2aa5e131f993685 to your computer and use it in GitHub Desktop.
live2drmmz.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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