Scene_Menu
; the title menu is Scene_Title
. That said, the latter is a great example of how to add sprites, so let's look at some of its code (rpg_scenes.js):Scene_Title.prototype.create = function() {
Scene_Base.prototype.create.call(this);
this.createBackground();
this.createForeground();
this.createWindowLayer();
this.createCommandWindow();
};
Scene_Title.prototype.createBackground = function() {
this._backSprite1 = new Sprite(ImageManager.loadTitle1($dataSystem.title1Name));
this._backSprite2 = new Sprite(ImageManager.loadTitle2($dataSystem.title2Name));
this.addChild(this._backSprite1);
this.addChild(this._backSprite2);
};
Scene_Title.prototype.createForeground = function() {
this._gameTitleSprite = new Sprite(new Bitmap(Graphics.width, Graphics.height));
this.addChild(this._gameTitleSprite);
if ($dataSystem.optDrawTitle) {
this.drawGameTitle();
}
};
Scene_Title.prototype.drawGameTitle = function() {
var x = 20;
var y = Graphics.height / 4;
var maxWidth = Graphics.width - x * 2;
var text = $dataSystem.gameTitle;
this._gameTitleSprite.bitmap.outlineColor = 'black';
this._gameTitleSprite.bitmap.outlineWidth = 8;
this._gameTitleSprite.bitmap.fontSize = 72;
this._gameTitleSprite.bitmap.drawText(text, x, y, maxWidth, 48, 'center');
};
Scene_Title.prototype.centerSprite = function(sprite) {
sprite.x = Graphics.width / 2;
sprite.y = Graphics.height / 2;
sprite.anchor.x = 0.5;
sprite.anchor.y = 0.5;
};
this._myPic = new Sprite(ImageManager.loadEnemy('Slime'));
this.addChild(this._myPic);
this._myPic.x = 50;
initialize
) and do the sprite stuff there; else you can just code it directly into your window's "start-up" method(s).Window_Base.prototype.drawFace = function(faceName, faceIndex, x, y, width, height) {
width = width || Window_Base._faceWidth;
height = height || Window_Base._faceHeight;
var bitmap = ImageManager.loadFace(faceName);
var pw = Window_Base._faceWidth;
var ph = Window_Base._faceHeight;
var sw = Math.min(width, pw);
var sh = Math.min(height, ph);
var dx = Math.floor(x + Math.max(width - pw, 0) / 2);
var dy = Math.floor(y + Math.max(height - ph, 0) / 2);
var sx = faceIndex % 4 * pw + (pw - sw) / 2;
var sy = Math.floor(faceIndex / 4) * ph + (ph - sh) / 2;
this.contents.blt(bitmap, sx, sy, sw, sh, dx, dy);
};
blt
takes source image coordinates (x, y, width, height) and destination coordinates (destination width/height are optional). Here you see it's drawing one face from the image, to a specific x
& y
in the window.