- Joined
- Oct 8, 2015
- Messages
- 365
- Reaction score
- 94
- First Language
- English
- Primarily Uses
- RMMV
So I'm working with the lovely MBS_FPLE plugin for MV and it has the ability to show sprite events in a first person dungeon crawler. However it only works with the sheets designed for 8 characters. I've spent several hours myself tinkering with the script, it seems like it would be relatively straight forward for those more familiar with math and all that ^_^.
The goal: Modify this to work with the simple 3 X 4 single character sprite sheet. sprite.cellIndex should end up being between 0 and 11 after all the math is done!
I could potentially live without the directional portion of this (and normally took it out when I was experimenting), Thanks for reading.
MBS.FPLE.Map.prototype._updateEvents = function(scene) {
this._events.forEach(function (sprite) {
var event = sprite._event;
var charIndex = event.characterIndex();
var row = 48;
var col = 3;
var offset = row * Math.floor(charIndex / 4) + (charIndex % 4) * col;
var direction;
if (!ImageManager.isObjectCharacter(event.characterName())) {
var eventAngle = ([0, 90, 270, 180])[event._direction / 2 - 1];
var playerAngle = $gamePlayer.cameraAngle();
var relativeAngle = playerAngle - eventAngle;
relativeAngle %= 360;
while (relativeAngle < 0)
relativeAngle += 360;
var relativeDirection = [180, 90, 270, 0].indexOf(relativeAngle) * 2 + 2;
direction = (relativeDirection / 2 - 1) % 4 * col * 4;
} else {
direction = (event._direction / 2 - 1) % 4 * col * 4;
}
sprite.position = new BABYLON.Vector3(-event._realX, MBS.FPLE.cameraHeight, event._realY);
sprite.cellIndex = offset + direction + ([0, 1, 2, 1])[event._pattern % 4];
});
Why not just use full sheets that have lots of empty space?
If I were to use 512pix assets that would result in a sheet over 6000 pixels wide!. So that would be a bad idea.
The goal: Modify this to work with the simple 3 X 4 single character sprite sheet. sprite.cellIndex should end up being between 0 and 11 after all the math is done!
I could potentially live without the directional portion of this (and normally took it out when I was experimenting), Thanks for reading.
MBS.FPLE.Map.prototype._updateEvents = function(scene) {
this._events.forEach(function (sprite) {
var event = sprite._event;
var charIndex = event.characterIndex();
var row = 48;
var col = 3;
var offset = row * Math.floor(charIndex / 4) + (charIndex % 4) * col;
var direction;
if (!ImageManager.isObjectCharacter(event.characterName())) {
var eventAngle = ([0, 90, 270, 180])[event._direction / 2 - 1];
var playerAngle = $gamePlayer.cameraAngle();
var relativeAngle = playerAngle - eventAngle;
relativeAngle %= 360;
while (relativeAngle < 0)
relativeAngle += 360;
var relativeDirection = [180, 90, 270, 0].indexOf(relativeAngle) * 2 + 2;
direction = (relativeDirection / 2 - 1) % 4 * col * 4;
} else {
direction = (event._direction / 2 - 1) % 4 * col * 4;
}
sprite.position = new BABYLON.Vector3(-event._realX, MBS.FPLE.cameraHeight, event._realY);
sprite.cellIndex = offset + direction + ([0, 1, 2, 1])[event._pattern % 4];
});
Why not just use full sheets that have lots of empty space?
If I were to use 512pix assets that would result in a sheet over 6000 pixels wide!. So that would be a bad idea.
Last edited by a moderator:
