camera shift left right

pasunna

Veteran
Veteran
Joined
Feb 3, 2019
Messages
289
Reaction score
69
First Language
thai
Primarily Uses
RMMV
Hi
I'm working on side scrolling game
and the Rpg Maker camera always lock to the center
I want make the camera adjust by player facing
right is -3 tile etc
and go make a shot in this

Code:
Game_Player.prototype.centerX = function() {
  var x = (Graphics.width / $gameMap.tileWidth() - 1) / 2.0;
  var d = this.direction();
  var i = 3;
  if(d === 4){
    x += i;
  }
  if(d === 6){
    x -= i;
  }
  return x;
};
but turn out it work only in negative way
like when face right the camera will shift to the left
image_20200227_103901.png
it's opposite of what I want
(the guy in picture suppose to stand on the left instead)
when I try to change the +/- sequence
another outcome just doesn't change anything and lock the character to center like default

So...
I try around on those

Code:
Game_Player.prototype.centerY = function() {
  var y =(Graphics.height / $gameMap.tileHeight() - 1) / 2.0;
  y += 1;
  return y;
  return (Graphics.height / $gameMap.tileHeight() - 1 + 3) / 2.0;
};
Game_Map.prototype.setDisplayPos = function(x, y) {
  //y += 3;
  if (this.isLoopHorizontal()) {
      this._displayX = x.mod(this.width());
      this._parallaxX = x;
  } else {
      var endX = this.width() - this.screenTileX();
      this._displayX = endX < 0 ? endX / 2 : x.clamp(0, endX);
      this._parallaxX = this._displayX;
  }
  if (this.isLoopVertical()) {
      this._displayY = y.mod(this.height());
      this._parallaxY = y;
  } else {
      var endY = this.height() - this.screenTileY();
      this._displayY = endY < 0 ? endY / 2 : y.clamp(0, endY);
      
      //this._displayY += 6;
      this._parallaxY = this._displayY;
  }
};

Game_Player.prototype.updateScroll = function(lastScrolledX, lastScrolledY) {
  var x1 = lastScrolledX;
  var y1 = lastScrolledY;
  var x2 = this.scrolledX();
  var y2 = this.scrolledY();
  if (y2 > y1 && y2 > this.centerY()) {
      $gameMap.scrollDown(y2 - y1);
  }
  if (x2 < x1 && x2 < this.centerX()) {
      $gameMap.scrollLeft(x1 - x2);
  }
  if (x2 > x1 && x2 > this.centerX()) {
      $gameMap.scrollRight(x2 - x1);
  }
  if (y2 < y1 && y2 < this.centerY()) {
      $gameMap.scrollUp(y1 - y2);
  }
};

Game_Map.prototype.scrollDown = function(distance) {
  if (this.isLoopVertical()) {
      this._displayY += distance;
      this._displayY %= $dataMap.height;
      if (this._parallaxLoopY) {
          this._parallaxY += distance;
      }
  } else if (this.height() >= this.screenTileY()) {
      var lastY = this._displayY;
      this._displayY = Math.min(this._displayY + distance,
          this.height() - this.screenTileY());
      this._parallaxY += this._displayY - lastY;
  }
};

Game_Map.prototype.scrollLeft = function(distance) {
  if (this.isLoopHorizontal()) {
      this._displayX += $dataMap.width - distance;
      this._displayX %= $dataMap.width;
      if (this._parallaxLoopX) {
          this._parallaxX -= distance;
      }
  } else if (this.width() >= this.screenTileX()) {
      var lastX = this._displayX;
      this._displayX = Math.max(this._displayX - distance, 0);
      this._parallaxX += this._displayX - lastX;
  }
};

Game_Map.prototype.scrollRight = function(distance) {
  if (this.isLoopHorizontal()) {
      this._displayX += distance;
      this._displayX %= $dataMap.width;
      if (this._parallaxLoopX) {
          this._parallaxX += distance;
      }
  } else if (this.width() >= this.screenTileX()) {
      var lastX = this._displayX;
      this._displayX = Math.min(this._displayX + distance,
          this.width() - this.screenTileX());
      this._parallaxX += this._displayX - lastX;
  }
};

Game_Map.prototype.scrollUp = function(distance) {
  if (this.isLoopVertical()) {
      this._displayY += $dataMap.height - distance;
      this._displayY %= $dataMap.height;
      if (this._parallaxLoopY) {
          this._parallaxY -= distance;
      }
  } else if (this.height() >= this.screenTileY()) {
      var lastY = this._displayY;
      this._displayY = Math.max(this._displayY - distance, 0);
      this._parallaxY += this._displayY - lastY;
  }
};
but can't find a good outcome too

thank you
 

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,066
Reaction score
443
First Language
Portuguese - Br
Primarily Uses
RMMV
I was about to do some code with this part of the camera too. But the minigame has occupied me a little. If no one helps you with his, If I found a way I will come here to tell you ^^
 

Raizen

Veteran
Veteran
Joined
Oct 24, 2012
Messages
228
Reaction score
237
First Language
Portuguese
Primarily Uses
RMMV
Ah I think there is a good way to do it, and in a much simpler way than what you are trying. One of my first plugins was a smooth camera slide, since I was learning JS there are some code smells on the code, but you can get the idea I was using.


Code:
//=============================================================================
// Ignis Smooth Camera Slide.js
//=============================================================================

/*:
 * @plugindesc Adds a smooth camera sliding when moving
 * @author Raizen
 *
 * @help This plugin does not provide plugin commands.
 *
  * @param Scroll X
 * @desc The speed in which the camera will move in the X axis (Higher = slower)
 * @default 20
  * @param Scroll Y
 * @desc The speed in which the camera will move in the Y axis (Higher = slower)
 * @default 20
 */


//(function() {
(function() {
var ignisParameters = PluginManager.parameters('Ignis Smooth Camera Slide');
 var ignisScrollX = parseInt(ignisParameters['Scroll X'] || 20);
 var ignisScrollY = parseInt(ignisParameters['Scroll Y'] || 20);
Game_Player.prototype.updateScroll = function(lastScrolledX, lastScrolledY) {
    var x1 = lastScrolledX;
    var y1 = lastScrolledY;
    var x2 = this.scrolledX();
    var y2 = this.scrolledY();
    if (y2 > this.centerY()) {
        $gameMap.scrollDown((y2 - this.centerY())/ignisScrollY);
    }
    if (x2 < this.centerX()) {
        $gameMap.scrollLeft((this.centerX() - x2)/ignisScrollX);
    }
    if (x2 > this.centerX()) {
        $gameMap.scrollRight((x2 - this.centerX())/ignisScrollX);
    }
    if (y2 < this.centerY()) {
        $gameMap.scrollUp((this.centerY() - y2)/ignisScrollY);
    }
};}    
)();
What I would do was just change the x axis putting something like this.
if (x2 < this.centerX()) {
$gameMap.scrollLeft((this.centerX() - x2)/ignisScrollX);
}

for

if (x2 < this.centerX()) {
$gameMap.scrollLeft((this.centerX() - x2 + this.xDirectionFix())/ignisScrollX);
}

and add this:

Game_Player.prototype.xDirectionFix = function(){
switch (this._direction){
case 2:
return 0;
case 4:
return -3;
case 6:
return 0;
case 8:
return 3;
};
};

Something like this haha, I didn't do it all since you posted on Learning Javascript, so I guess you want to do it yourself xD, but I gave an idea of how I would do it.
 

pasunna

Veteran
Veteran
Joined
Feb 3, 2019
Messages
289
Reaction score
69
First Language
thai
Primarily Uses
RMMV
Ah I think there is a good way to do it, and in a much simpler way than what you are trying. One of my first plugins was a smooth camera slide, since I was learning JS there are some code smells on the code, but you can get the idea I was using.


Code:
//=============================================================================
// Ignis Smooth Camera Slide.js
//=============================================================================

/*:
* @plugindesc Adds a smooth camera sliding when moving
* @author Raizen
*
* @help This plugin does not provide plugin commands.
*
  * @param Scroll X
* @desc The speed in which the camera will move in the X axis (Higher = slower)
* @default 20
  * @param Scroll Y
* @desc The speed in which the camera will move in the Y axis (Higher = slower)
* @default 20
*/


//(function() {
(function() {
var ignisParameters = PluginManager.parameters('Ignis Smooth Camera Slide');
var ignisScrollX = parseInt(ignisParameters['Scroll X'] || 20);
var ignisScrollY = parseInt(ignisParameters['Scroll Y'] || 20);
Game_Player.prototype.updateScroll = function(lastScrolledX, lastScrolledY) {
    var x1 = lastScrolledX;
    var y1 = lastScrolledY;
    var x2 = this.scrolledX();
    var y2 = this.scrolledY();
    if (y2 > this.centerY()) {
        $gameMap.scrollDown((y2 - this.centerY())/ignisScrollY);
    }
    if (x2 < this.centerX()) {
        $gameMap.scrollLeft((this.centerX() - x2)/ignisScrollX);
    }
    if (x2 > this.centerX()) {
        $gameMap.scrollRight((x2 - this.centerX())/ignisScrollX);
    }
    if (y2 < this.centerY()) {
        $gameMap.scrollUp((this.centerY() - y2)/ignisScrollY);
    }
};} 
)();
What I would do was just change the x axis putting something like this.
if (x2 < this.centerX()) {
$gameMap.scrollLeft((this.centerX() - x2)/ignisScrollX);
}

for

if (x2 < this.centerX()) {
$gameMap.scrollLeft((this.centerX() - x2 + this.xDirectionFix())/ignisScrollX);
}

and add this:

Game_Player.prototype.xDirectionFix = function(){
switch (this._direction){
case 2:
return 0;
case 4:
return -3;
case 6:
return 0;
case 8:
return 3;
};
};

Something like this haha, I didn't do it all since you posted on Learning Javascript, so I guess you want to do it yourself xD, but I gave an idea of how I would do it.
Wow! This is more simplify way than I thought
I'm not good on math so obliviously I will not find a solution like that
I took like 6 hr to confuse why it's always work only one way adjust
and it's weird that when use direction(4/6 number) input it works
so...because of that equation

but now as it's working like charm
your smooth camera is bypass the map edge camera function
Did you have solution about that?

-----------------
edit
oh... wait... weird....
the flip had problem with it in sometime not every time
not sure what is the bug
but maybe I will not use this in the end if it too complicate
because the effect of flip camera look a bit annoying in action...

thank you very much
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts

Ami
4 days im not using my laptop to waiting someone to reinstall (sigh)
Stream will be live shortly with some Donkey Kong 64! Feel free to drop by!
Working on a test Boss for the new No Travel Game Jam
- Name Plugin by Moghunter -
Free RPG Maker Ready Charging Up Animation

Enjoy -No Credit Needed But Appreciated -
Download it at https://lvgames.itch.io/free-charging-up-pixel-animation-fx-rpg-maker-ready
:/ .... so, thought I’d go to the park to sit in the cool breeze and get out of the house a little. Nope, guess that’s quarantined too. Ok...

Forum statistics

Threads
95,486
Messages
929,524
Members
125,733
Latest member
whypzk
Top