Move Camera with Mouse

Status
Not open for further replies.

Scheikowski

Villager
Member
Joined
Apr 11, 2018
Messages
13
Reaction score
1
First Language
Turkish
Primarily Uses
RMMV
I've already searched for it but i couldn't find any script. What I'm looking for is move the camera with mouse like in all strategy games. If player brings mouse cursor to right border of the screen then camera moves to the right. If up then camera moves to the up.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
149
Reaction score
173
First Language
Danish
Primarily Uses
RMMV
I made this plugin for you :)
I added some parameters so you can choose how close the mouse should be by the border in order to move the camera and at which speed.
I also added a option for if you want the camera to always show the player when they are moving.

You can also use a plugin command to turn of/on the plugin: CameraMouseMove On/Off/Toggle

Code:
//=============================================================================
// Camera Mouse Move
// MRP_CameraMouseMove.js
// By Magnus0808 || Magnus Rubin Peterson
//=============================================================================
/*:
 * @plugindesc Camera moves when the mouse is at edge of screen.
 * @author Magnus0808
 *
 * @help Plug and play for default settings.
 * The following plugin command can be used to turn off/on the plugin:
 * CameraMouseMove On/Off/Toggle (depending on what you want)
 *
 * @param Border Distance
 * @type Number
 * @desc The distance the mouse should be from the border to move the camera.
 * @default 50
 *
 * @param Move Speed
 * @type Number
 * @decimals 2
 * @desc The speed the camera will move with when the mouse is by the border.
 * @default 0.10
 *
 * @param Always Show Player Move
 * @type Boolean
 * @desc If true then when the player moves the camera will always show it.
 * @default true
*/

(function(){
    var CameraMouseMove = {};
    CameraMouseMove.Parameters = PluginManager.parameters('MRP_CameraMouseMove');
    CameraMouseMove.on = true;
    CameraMouseMove.borderDistance = Number(CameraMouseMove.Parameters['Border Distance']);
    CameraMouseMove.moveSpeed = Number(CameraMouseMove.Parameters['Move Speed']);
    CameraMouseMove.playerCenter = (String(CameraMouseMove.Parameters['Always Show Player Move']) == 'true');
    
    var MRP_CMM_GI_PLUGINCOMMAND_OLD = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        MRP_CMM_GI_PLUGINCOMMAND_OLD.call(this, command, args)
        
        if (command === 'CameraMouseMove'){
            switch(args[0].toLowerCase()){
                case "on":
                    CameraMouseMove.on = true;
                    break;
                case "off":
                    CameraMouseMove.on = false;
                    break;
                case "toggle":
                    CameraMouseMove.on = !CameraMouseMove.on;
                    break;
            }
        }
    };
    
    var MRP_CMM_GM_UPDATE_OLD = Game_Map.prototype.update;
    Game_Map.prototype.update = function(sceneActive) {
        MRP_CMM_GM_UPDATE_OLD.call(this, sceneActive);
        this.updateCamera();
    };
    
    Game_Map.prototype.updateCamera = function(){
        if(CameraMouseMove.on) {
            var mouseX = TouchInput._mouseX;
            var mouseY = TouchInput._mouseY;
            
            if(mouseX < CameraMouseMove.borderDistance) this.scrollLeft(CameraMouseMove.moveSpeed);
            if(mouseY < CameraMouseMove.borderDistance) this.scrollUp(CameraMouseMove.moveSpeed);
            if(mouseX > Graphics.boxWidth - CameraMouseMove.borderDistance) this.scrollRight(CameraMouseMove.moveSpeed);
            if(mouseY > Graphics.boxHeight - CameraMouseMove.borderDistance) this.scrollDown(CameraMouseMove.moveSpeed);
        }   
    }
    
    var MRP_CMM_GP_UPDATESCROLL_OLD = Game_Player.prototype.updateScroll;
    Game_Player.prototype.updateScroll = function(lastScrolledX, lastScrolledY) {
        MRP_CMM_GP_UPDATESCROLL_OLD.call(this, lastScrolledX, lastScrolledY);   
        if(CameraMouseMove.playerCenter && this.isMoving()){
            if(this._realX + 1 < $gameMap._displayX) {
                $gameMap.scrollLeft($gameMap._displayX + this.centerX() - this._realX);
            }
            if(this._realX - 1 > $gameMap._displayX + this.centerX() * 2) {
                $gameMap.scrollRight(this._realX - $gameMap._displayX + this.centerX() * 2);
            }
            if(this._realY + 1 < $gameMap._displayY) {
                $gameMap.scrollUp($gameMap._displayY + this.centerY() - this._realY);
            }
            if(this._realY -1 > $gameMap._displayY + this.centerY() * 2) {
                $gameMap.scrollDown(this._realY - $gameMap._displayY + this.centerY() * 2);
            }   
        }
        
    };
    
    var MRP_CMM_TI_ONMOUSEMOVE = TouchInput._onMouseMove;
    TouchInput._onMouseMove = function(event) {
        MRP_CMM_TI_ONMOUSEMOVE.call(this, event);
        this._mouseX = Graphics.pageToCanvasX(event.pageX);
        this._mouseY = Graphics.pageToCanvasY(event.pageY);
    };
    
})();
 

Attachments

Scheikowski

Villager
Member
Joined
Apr 11, 2018
Messages
13
Reaction score
1
First Language
Turkish
Primarily Uses
RMMV
Thanks a lot Magnus0808. This is exactly what I want!
 

Zack Phoenix

Artist
Veteran
Joined
Jun 12, 2013
Messages
187
Reaction score
26
First Language
German
Primarily Uses
RMMV
This is gonna be essential for any game using one of the tactical combat plugins! And just super useful all around. Thanks!
 

Sunjean

Veteran
Veteran
Joined
Oct 18, 2019
Messages
61
Reaction score
23
First Language
Norvegian
Primarily Uses
RMMV
Just what I was looking for!
Tested it just now, and it works like a charm :) Found move speed 0.20 to be perfect.

Thank you Magnus0808.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,013
Reaction score
5,326
First Language
Dutch
Primarily Uses
RMXP

sunjean, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Profile Posts

While we prepare the official trailer, enjoy this kind-of-second teaser! ^^
-Ele
New Episodes of RPG Shenanigans Uploaded to Youtube!

Episode 5 - Surprise Party!
Youtube Link:
Episode 6 - Killer Gin
Youtube Link:
Episode 7 - Gaia's Melody: Echoed Melodies
(Coming soon!)

Episode 8 - Clarent Saga: Tactics
(Coming soon!)

Episode 9 - Star Shift
(Coming soon!)
When the Map Generator throws in the assets in the most dumbest way possible - your path is blocked :D

I went to sleep at 3 am because of my anxiety. Set up my alarm for 7 am so that I could have sasagues for breakfast and do morning routine before lessons starts at 8 am. I knew I wouldn't be able to sleep even after my lessons finished because I have to visit my grandparents today I was sad bc I was really tired. Thats when I realised. My lesson starts at 9 am. I could get one extra hour of sleep if I didnt forget it

Forum statistics

Threads
107,559
Messages
1,030,551
Members
139,672
Latest member
WDRS
Top