Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Clicking and Dragging to Move the Camera?

Let's say in a battle scene where the player cannot move independently or anything of that sort (a plugin is used to disable movement), an enemy is offscreen. How would one set up the game so that if they hold down the right mouse button (I have an input mapping script) they can essentially click and drag to move the camera around so that the player can see the enemy? (I have the rest sorted, I just need this design thing worked around as not everyone will use the same screen resolutions and thus may see less or more of the situation than others)
 

Simmons

Villager
Xy$
0.00
I'm currently working on this. I haven't got a nice plugin for you but might be able to point you in the right direction.

First I copied the TouchInput static class and renamed it MouseInput (see attached). Using this you can get the start and current x/y coords of the drag. In the Scene_Map I altered a few methods and added this to the updateDestination method.

JavaScript:
if (MouseInput.isRightDragged()) {

        var startX = $gameMap.canvasToMapX(MouseInput._startX);
        var startY = $gameMap.canvasToMapY(MouseInput._startY);

        var x = $gameMap.canvasToMapX(MouseInput.x);
        var y = $gameMap.canvasToMapY(MouseInput.y);

        var movedX = startX - x;
        var movedY = startY - y;

        if (movedX != 0 || movedY != 0) {

            var endX = $gameMap.width() - $gameMap.screenTileX();

            var endY = $gameMap.height() - $gameMap.screenTileY();

            $gameMap._displayX = ($gameMap._displayX + (movedX - this._moveDistX)).clamp(0, endX);
            $gameMap._displayY = ($gameMap._displayY + (movedY - this._moveDistY)).clamp(0, endY);

            this._moveDistX = movedX;
            this._moveDistY = movedY;
        }

    } else {
        this._moveDistX = 0;
        this._moveDistY = 0;
    }
You will need to add the _moveDist variables to the class as well as alter the default movement code. I'm still working through this myself but did manage to get this to work by commenting out normal movement, menu, etc.

Probably better to override TouchInput as well instead of creating a separate Input helper. If you go with MouseInput you will need to add the update and initialize calls to the SceneManager.

Good luck
 

Attachments

Top