lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
324
Reaction score
188
First Language
English
Primarily Uses
RMMZ
So I'm delving into a new section of the RM code that I haven't worked with yet - the display/camera positioning and I would like some help in trying to understand it. Specifically:

What I Want:
For the 'camera' to move in front of the player while moving (+1 tile, +2 tiles if dashing) and centered on player when standing still.

I've seen this effect in other games and will admit "I want it too" lol. Also this is a style I feel I want for my game but not sure how to do it (mind "How To Do It", not "download and install X plugin") :p ... unless of course downloading said plugin is not obfuscated and is free to learn from without any copywrite issues. I don't want to steal the code, but I would need to look at it and reverse-engineer it so I can do it too. /endrant
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,048
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
You might only need to patch the centerX and centerY methods of Game_Player. I.e. offset the default x/y position according to the player's current direction and whether or not they're dashing.
 

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
324
Reaction score
188
First Language
English
Primarily Uses
RMMZ
EDIT: center method is not working as intended :\ How to explain it.. when moving where the "centered" point would scroll the map, it scrolls keeping centered +/- 1 (X,Y) as intended but then it sticks there when moving back up or over, etc.

I'm going to try going back to my original idea, somehow scrolling +/- (X,Y) when moving, and then update $gamePlayer's update() and updateDashing() methods I think... might be the key in there... but I'll do that tomorrow. Am tired from coding all day xD


You might only need to patch the centerX and centerY methods of Game_Player. I.e. offset the default x/y position according to the player's current direction and whether or not they're dashing.
Will try that. My early experiment was with executeMove(Game_Player). Current problem list with this method are:
- The scroll doesn't happen until the move is executed (no doubt from an update method)
- It didn't recenter after moving, thus ending up with the camera continuing (if stuck on an object) while the directional button is pressed (Had the camera move up to +2 tiles ahead) and ended up with mapX+6, mapY+6 going diagonal lol

So I'll try messing with centerX and centerY first and see if that might be easier.
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,048
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
EDIT: center method is not working as intended :\ How to explain it.. when moving where the "centered" point would scroll the map, it scrolls keeping centered +/- 1 (X,Y) as intended but then it sticks there when moving back up or over, etc.
Ah. On closer inspection, player movement only scrolls the map if the display coordinates have moved the player away from their "center" position. I assume it's like that so the Scroll Map command can work...if you never use that command then you could try simply overriding the Game_Player#updateScroll method with a version that doesn't include those checks, e.g.
  • if (y2 > y1 && y2 > this.centerY()) { -> if (y2 > y1) {

Otherwise, as well as the centerX & centerY offsets, I think you'd need to manually scroll the map when the player starts/stops moving/dashing. Perhaps hook into Game_Player#update for that, e.g.
JavaScript:
(alias => {
  Game_Player.prototype.update = function() {
    const wasMoving  = this.isMoving();
    const wasDashing = this.isDashing();
    alias.apply(this, arguments);
    if (wasMoving !== this.isMoving()) {
      if (!wasMoving) {
        // started moving
      } else {
        // stopped moving
      }
    }
    if (wasDashing !== this.isDashing()) {
      if (!wasDashing) {
        // started dashing
      } else {
        // stopped dashing
      }
    }
  };
})(Game_Player.prototype.update);
(Be careful with isMoving: by default it returns true when centered on a tile, i.e. 1 frame per tile of movement.)

For a smooth transition between stand/walk/dash positions, you'll also need to manually code that smooth transition. Maybe hook into Game_Player#updateScroll for that, and refer to the startScroll & updateScroll methods of Game_Map for a possible approach to smoothing.

I did another quick search for relevant plugins...I found Galv's, but I don't think it offers this exact feature. Here's a link anyway, in case it helps~
 

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
324
Reaction score
188
First Language
English
Primarily Uses
RMMZ
I did another quick search for relevant plugins...I found Galv's, but I don't think it offers this exact feature. Here's a link anyway, in case it helps~
Yeah I found that too, looked into it. The camera trails behind the player, but it could be a start in the right direction. Also I must say you have an interesting way to alias methods.. I usually go with something like:

JavaScript:
const gamePlayer_update = Game_Player.prototype.update;
Game_Player.prototype.update = function(sceneActive) {
    gamePlayer_update.call(this, sceneActive);
    // Other code
};
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,048
Reaction score
2,358
First Language
EN
Primarily Uses
RMMZ
Also I must say you have an interesting way to alias methods..
I'm mostly self-taught so I probably have some strange programming habits. :kaoswt:

That said, I would recommend using apply(this, arguments) instead of call(this, arg1, etc). The first passes all received arguments to the original method, which might be important for plugin compatibility. :kaohi:
 

lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
324
Reaction score
188
First Language
English
Primarily Uses
RMMZ
EDIT: So I think I am making progress... I have modified the updateScroll(Game_Player) method to now where it is smoothly sliding rather than locked/following the player. So now trying to figure how to get it to slide in front of the player instead of trailing behind.

Currently looking into how/where those calls are made and I think I'm getting there.
> when moveStraight(Game_CharacterBase) is called, it updates "this._x" and "this._y" to be the destination point, while "this._realX" and "this._realY are the origin point (hence why "isMoving()" and "updateMove" functions use those 4 variables..

> So understanding that, I might try to make a function for updateScroll(Game_Player) to INSTEAD OF using scrolledX() and scrolledY() - which run off of "this._realX" and "this._realY" to calculate the "this._x" and "this._y" positions... or at least go from there.


I'm mostly self-taught so I probably have some strange programming habits. :kaoswt:

That said, I would recommend using apply(this, arguments) instead of call(this, arg1, etc). The first passes all received arguments to the original method, which might be important for plugin compatibility. :kaohi:
As does
JavaScript:
call(this, ...arguments)
;)
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Went to the doctor because I was actually sick and it was covered over with healthy people from a factory shift who all had to get negative covid tests to go back to work because one of their shift mates got it. Waited for several hours to find out that my low-grade fever, chills, light-headedness and fatigue were in fact covid...
And here I thought I've lost my music sense. Good exercise once in a while
Made Edits to a Character Art from 'Hibiki Katakura MV Monsters' (DLC), to Look More like One of My Own Characters. :LZScheeze:

Decided to retake an old concept I was working on long ago, first change I decided to tackle on right away is the sprites. Never been fan of the default chibis, so I edited it a bit... :kaoswt:
8YavqRj.png

Not sure if this will be the final take, but I like it more than the regular one.
Need a few testers for my new plugin, any takers?

Forum statistics

Threads
118,533
Messages
1,116,725
Members
155,565
Latest member
zenciyarraq
Top