lordvalinar

Lord of the Damned
Veteran
Joined
Mar 31, 2013
Messages
327
Reaction score
192
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,509
Reaction score
2,635
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
327
Reaction score
192
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,509
Reaction score
2,635
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
327
Reaction score
192
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,509
Reaction score
2,635
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
327
Reaction score
192
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

Beep-Beep-Motha-facka.gif

Just finished and uploaded the delivery truck base/sprite sheet. I've been steadily replacing the default assets with early modern alternatives. The air-ship for a biplane, horse-drawn wagon for a delivery truck, and next a sailboat for a steam-powered passenger liner (think of the SS Olympic and RMS Titanic).
I caught a shiny magikarp on pokemonGO today AND finally saw Detective Pikachu and it was so cute and I'm still so hype AHHHHH!!!
one of the coolest things I've learned from the forums is the ability to give yourself a hitbox. I have a move you can do on the fields. shoulder tackle. thanks to the forums, that tackle triggers self A switches on some events. NPC's and the environment now react to the tackle. awesome.
I really liked how this one turned out! :kaopride:
WYqMPf6.png

Character (Yes, this is a character): Nibiru the Primal Being from Yugioh.
Dragon Quest style enemy selection plugin work in progress:

Quest_Targeting.png

It's a simple targeting system from the NES era. Select an enemy group; single-target skills will target the first enemy in that group.

Quest-Targeting-Animated.gif

Forum statistics

Threads
121,946
Messages
1,145,357
Members
160,218
Latest member
Tarasyring
Top