|
//-----------------------------------------------------------------------------
// Sprite_Picture
// 图片精灵
// The sprite for displaying a picture.
// 显示图片的精灵
function Sprite_Picture() {
this.initialize.apply(this, arguments);
}
Sprite_Picture.prototype = Object.create(Sprite.prototype);
Sprite_Picture.prototype.constructor = Sprite_Picture;
//初始化
Sprite_Picture.prototype.initialize = function(pictureId) {
Sprite.prototype.initialize.call(this);
this._pictureId = pictureId;
this._pictureName = '';
this.update();
};
//图片
Sprite_Picture.prototype.picture = function() {
return $gameScreen.picture(this._pictureId);
};
//更新
Sprite_Picture.prototype.update = function() {
Sprite.prototype.update.call(this);
this.updateBitmap();
if (this.visible) {
this.updateOrigin();
this.updatePosition();
this.updateScale();
this.updateTone();
this.updateOther();
}
};
//更新位图
Sprite_Picture.prototype.updateBitmap = function() {
var picture = this.picture();
if (picture) {
var pictureName = picture.name();
if (this._pictureName !== pictureName) {
this._pictureName = pictureName;
this.loadBitmap();
}
this.visible = true;
} else {
this._pictureName = '';
this.bitmap = null;
this.visible = false;
}
};
//更新原点
Sprite_Picture.prototype.updateOrigin = function() {
var picture = this.picture();
if (picture.origin() === 0) {
this.anchor.x = 0;
this.anchor.y = 0;
} else {
this.anchor.x = 0.5;
this.anchor.y = 0.5;
}
};
//更新位置
Sprite_Picture.prototype.updatePosition = function() {
var picture = this.picture();
this.x = Math.floor(picture.x());
this.y = Math.floor(picture.y());
};
//更新比例
Sprite_Picture.prototype.updateScale = function() {
var picture = this.picture();
this.scale.x = picture.scaleX() / 100;
this.scale.y = picture.scaleY() / 100;
};
//更新色调
Sprite_Picture.prototype.updateTone = function() {
var picture = this.picture();
if (picture.tone()) {
this.setColorTone(picture.tone());
} else {
this.setColorTone([0, 0, 0, 0]);
}
};
//更新其他
Sprite_Picture.prototype.updateOther = function() {
var picture = this.picture();
this.opacity = picture.opacity();
this.blendMode = picture.blendMode();
this.rotation = picture.angle() * Math.PI / 180;
};
//读取位图
Sprite_Picture.prototype.loadBitmap = function() {
this.bitmap = ImageManager.loadPicture(this._pictureName);
};
站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作
GMT+8, 2024-5-13 02:59
Powered by Discuz! X3.1
© 2001-2013 Comsenz Inc.