こんにちは、今日はRPGツクールMVの自作プラグインで独自の画面に任意の画像を表示する方法についてまとめていきます。
確認環境
RPGツクールMV Version 1.6.2
画像を表示する方法
画像を表示するのにjs/rpg_core.jsに定義されているSpriteクラスを使用します。
以下のようにSpriteクラスのインスタンスを生成し、addChild()でシーンに追加します。
1 2 3 4 5 6 | var sprite = new Sprite(ImageManager.loadEnemy( "Angel" )); sprite.x = Graphics.width / 2; sprite.y = Graphics.height / 2; sprite.anchor.x = 0.5; sprite.anchor.y = 0.5; this .addChild(sprite); |
ImageManager.loadEnemy関数は指定の画像名をimg/enemies/フォルダから探して画像を生成します。
内部的にはImageManager.loadBitmapで画像を生成する際にフォルダを固定しているのみなので、ImageManager.loadBitmap自体を使用しても問題ありません。
そのほかにも以下のような関数が用意されています。
いずれもjs/rpg_managers.jsの803行目あたりから定義されていますので、確認してみてください。
関数名 | フォルダ |
loadAnimation | img/animations/ |
loadBattleback1 | img/battlebacks1/ |
loadBattleback2 | img/battlebacks2/ |
loadEnemy | img/enemies/ |
loadCharacter | img/characters/ |
loadFace | img/faces/ |
loadParallax | img/parallaxes/ |
loadPicture | img/pictures/ |
loadSvActor | img/sv_actors/ |
loadSvEnemy | img/sv_enemies/ |
loadSystem | img/system/ |
loadTileset | img/tilesets/ |
loadTitle1 | img/titles1/ |
loadTitle2 | img/titles2/ |
サンプル
プラグインコマンド「TestScene」で独自のシーンを呼び出し、そのシーン内で天使の画像を表示、上下左右キーで移動させるサンプルです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | ( function () { var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; Game_Interpreter.prototype.pluginCommand = function (command, args) { _Game_Interpreter_pluginCommand.call( this , command, args); switch (command){ case 'TestScene' : SceneManager.push(Scene_Test); break ; } }; //-------------------------------------------------- // Name : Scene_Test // Desc : テストシーンクラス //-------------------------------------------------- function Scene_Test() { this .initialize.apply( this , arguments); } Scene_Test.prototype = Object.create(Scene_Base.prototype); Scene_Test.prototype.constructor = Scene_Test; Scene_Test.prototype.initialize = function () { Scene_Base.prototype.initialize.call( this ); }; Scene_Test.prototype.create = function () { Scene_Base.prototype.create.call( this ); this .createBackground(); this .createSprite(); }; Scene_Test.prototype.createSprite = function () { var sprite = new Sprite(ImageManager.loadEnemy( "Angel" )); sprite.x = Graphics.width / 2; sprite.y = Graphics.height / 2; sprite.anchor.x = 0.5; sprite.anchor.y = 0.5; this ._testSprite = sprite; this .addChild( this ._testSprite); } Scene_Test.prototype.update = function () { Scene_Base.prototype.update.call( this ); this .keyControll(); }; Scene_Test.prototype.keyControll = function () { if (Input.isRepeated( 'cancel' )) { this .popScene(); } if (Input.isPressed( 'left' )) { this ._testSprite.x -= 10; } if (Input.isPressed( 'right' )) { this ._testSprite.x += 10; } if (Input.isPressed( 'up' )) { this ._testSprite.y -= 10; } if (Input.isPressed( 'down' )) { this ._testSprite.y += 10; } } Scene_Test.prototype.createBackground = function () { this ._backgroundSprite = new Sprite(); this ._backgroundSprite.bitmap = SceneManager.backgroundBitmap(); this .addChild( this ._backgroundSprite); }; })(); |