- Joined
- Feb 3, 2019

- Messages
- 289

- Reaction score
- 69

- First Language
- thai

- Primarily Uses
- RMMV

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;
};
```

like when face right the camera will shift to the left

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;
}
};
```

thank you