8 Directions Sprites in MV

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
106
Reaction score
20
First Language
Italian
Hi,


 I programmed an 8 dir code and i wanted to implement and 8 dir sprite system. since the sprite system seems a little bit messy/unclear, before spending some time trying to figure how to do it maybe someone knows where I should be looking for in the code or what i have to do in a general or specific way. Anyone does know how to do it?
 

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
106
Reaction score
20
First Language
Italian
never mind I came out with a aimple solution. If anyone wanna know:


I created a dir8 variable that holds the 8 direction number:
In Game_CharacterBase.prototype.updateMove i call the change of the value based upon the current character movement if the direction isn't fixed


in Game_CharacterBase.prototype.setImage ,when given the image file, checks if the image has "dir8" in the name, in that case sets this._isDir8 (which i created) true


Basically from now on if the character is a dir8 cahracter (_dir8 is true) and it faces in the 4 basic directions it sets the index of the graphic (the character u choose upon the 8 when u give the graphic) as the original index, instead if he faces a diagonal direction it sets the index to the original index + 4 and basically it chooses the character below, which holds the graphic of the character facing the diagonal directions.


I hope it's not too gibberish and someone will find this usefull


below is an example of the sprite i'm using for testing:


grafica_8dir.png


EDIT: I changed the code to make it clean


var alias_Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
Game_CharacterBase.prototype.initMembers = function() {
alias_Game_CharacterBase_initMembers.call(this); //calls original method

this._dir8 = this._direction;
this._isDir8 = false;
};

var alias_CharacterBase_update = Game_CharacterBase.prototype.update
Game_CharacterBase.prototype.update = function() {
alias_CharacterBase_update.call(this); //calls original method

// added lines
this.updateDir8();
};

Game_CharacterBase.prototype.setImage = function(characterName, characterIndex) {
this._tileId = 0;
this._characterName = characterName;
this._characterIndex = characterIndex;
this._isObjectCharacter = ImageManager.isObjectCharacter(characterName);

// added lines
this._isDir8 = ImageManager.is8DirCharacter(characterName);
this._originalCharacterIndex = (this._isDir8 && this._characterIndex > 3) ? this._characterIndex - 4 : this._characterIndex;
};

Game_CharacterBase.prototype.setDirection = function(d) {
if (!this.isDirectionFixed() && d) {

var dir4;
switch (d) {
case 1:
dir4 = 2;
break;
case 3:
dir4 = 6;
break;
case 7:
dir4 = 4;
break;
case 9:
dir4 = 8;
break;
default:
dir4 = d;
}

this._direction = dir4;
this._dir8 = d;
}

this.resetStopCount();
};

Game_CharacterBase.prototype.updateDir8 = function() {
if (this._isDir8) {
if (Math.isEven(this._dir8)) {
// direzione a croce
this._characterIndex = this._originalCharacterIndex;
}
else {
// direzione in diagonale
this._characterIndex = this._originalCharacterIndex + 4;
}
}
};

Game_CharacterBase.prototype.moveDiagonally = function(horz, vert) {
this.setMovementSuccess(this.canPassDiagonally(this._x, this._y, horz, vert));
if (this.isMovementSucceeded()) {
this._x = $gameMap.roundXWithDirection(this._x, horz);
this._y = $gameMap.roundYWithDirection(this._y, vert);
this._realX = $gameMap.xWithDirection(this._x, this.reverseDir(horz));
this._realY = $gameMap.yWithDirection(this._y, this.reverseDir(vert));
this.increaseSteps();
}

if (horz == 4) {
if (vert == 2) this.setDirection(1);
else this.setDirection(7);
} else {
if (vert == 2) this.setDirection(3);
else this.setDirection(9);
}
};


basically all you after implementing this code is to add "8dir" to the name of the file (wherever you want) and put the diagonal movement graphics right below the standard one, as if they where the graphics of another character. At this point you can choose either one when assigning the graphic.
 
Last edited by a moderator:

atma505

Villager
Member
Joined
Aug 1, 2017
Messages
6
Reaction score
2
First Language
English
Primarily Uses
RMMV
Hmm, this was the error that I got ("ImageManager.is8DirCharacter is not a function"):


Was there something in the core code that was edited first? I realize this is a very old thread and I'm probably missing a more modern plugin somewhere :hswt:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,040
Members
137,569
Latest member
Shtelsky
Top