I'm currently developing a plugin that allows me to manipulate pictures with different transformations (translation, mirroring, rotation, scaling, ...), according to origins based on the following 9 coordinate points:
Code:
X---X---X
| | |
X---X---X
| | |
X---X---X
All the transformations are working independently as expected. However, I have a problem with the origin management. For example, if I position a picture on X and Y coordinates based on the top left origin, and then try a rotation based on the bottom left origin, the origin point moves to the original X/Y coordinates and my image ends up rotated in the wrong place.
After a long analysis of the code (and a lot of headaches to understand how it works), I discovered that the Sprite_Picture object had only one possible anchor, via this function (original code from rmmz_sprites.js):
Code:
Sprite_Picture.prototype.updateOrigin = function() {
const 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;
}
};
This means that each transformation can only be linked to one origin at a time. And as the picture sprite is updated with each game frame, if the origin changes, all the dimensions (X/Y position, X/Y scale, angle) are readjusted to this origin, causing the unwanted edge effect.
Code:
Sprite_Picture.prototype.update = function() {
Sprite_Clickable.prototype.update.call(this);
this.updateBitmap();
if (this.visible) {
this.updateOrigin();
this.updatePosition();
this.updateScale();
this.updateTone();
this.updateOther();
}
};
Please note that, apart from a function for resetting all transformations made on a picture, each transformation controlled by my plugin is independent of the others (contrary to the standard Move Picture function in RMMZ).
So in your opinion, is it possible to manage several origins per transformation (origin for positioning, origin for rotation, origin for scaling, etc.) with the Sprite_Picture object? Or is this a limitation of the PIXI.Sprite object (subsequently inherited by all RMMZ's Sprite_* objects)? And what solution could be envisaged to get around this problem (if any)?
Thank you in advance for any help or suggestions.
PS: For your information, the code currently under development for my plugin, if you want to test some ideas:
raw code (gitlab).