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,360
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,360
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,360
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 Profile Posts

SF_People3_3 added!
index.php

ScreenShot_1_3_2022_1_32_12.png
I feel QSprite for MV is underrated. I basically am able to use my chibi sideview battlers I drew on the maps and have all the motions available. this'll help a lot with cutscenes.
I've figured out how to reasonably tall-ify chibi sprites on my editor. I like that making tall sprites gives me control on expressing how tall characters seem on the field relative to each other as well as better differentiate adult sprites from child sprites.
doing some wacky experimental stuff in MV right now :kaoluv: I cannot wait to drop what I've been working on
Doing RPG Maker News for this week. (January 14th - 20th, 2022)

Forum statistics

Threads
118,554
Messages
1,116,925
Members
155,594
Latest member
000dsdsc
Top