Movement and Clickable Events in Map

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
I have a question about the character movement when the mouse is clicked in the map. I created a Sprite_Button on the map and placed it exactly on Spriteset_Map. When you click the sprite button it takes you somewhere, it works fine. My problem is that when I click it, my character moves to that direction as well. Any way to distinguish the sprite button as button, so when I click it my character would stay on its position and not recognize it as a mouse gesture for movement?
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
You can probably create some variable in Game_Temp, and add a condition inside the .isDestinationValid() that the new variable also has to be true. And in your button class set that new variable to true or false if the mouse is over it, using the .isButtonTouched() from the button class. If you're dealing with multiple buttons you could probably make that new variable an array, and every time you hover over a button add the button in that array only if it isn't already in it, and when you're not over it, remove it only if it's inside the array. Then in the .isDestinationValid() check if that array length is 0.

You might also be able to just use the $gameTemp.clearDestination() when ever you're hovering over your button. But that would probably depend on which class gets updated first, the player or the button.

I had to deal with this when making a touch hud. My approach is almost the same as my first idea, but instead I put the "canClick" variable inside Game Player, and added the new condition inside Scene_Map.prototype.processMapTouch() since I was already overriding it in my movement plugin.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
It works well now, it steps 1 tile though. What I did was to overwrite isDestinationValid that when the new variable from game temp is false then it would work the default way, when true it would just do nothing. I'll try to experiment what causes the character to move one tile before stopping the movement.
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
You might also be able to put it inside the Game_Temp.prototype.setDestination function and don't set the values if that variable is true. But it might probably be the same as putting it inGame_Temp.prototype isDestinationValid, but would be worth a try.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
The character still moves one tile. Here's how I did it:

Game_Temp.prototype.setDestination = function(x, y) { if ($gameTemp._menuButtonClicked) { this._destinationX = 0; this._destinationY = 0; } else { this._destinationX = x; this._destinationY = y; } };and in the move by Input, I did this:

Code:
	Game_Player.prototype.moveByInput = function() {	    if (!this.isMoving() && this.canMove()) {	        var direction = this.getInputDirection();	        if (direction > 0) {	            $gameTemp.clearDestination();	        } else if ($gameTemp.isDestinationValid()){	        	if (!$gameTemp._menuButtonClicked) {		            var x = $gameTemp.destinationX();		            var y = $gameTemp.destinationY();		            direction = this.findDirectionTo(x, y);	        	} else {	        		$gameTemp.clearDestination();	        	}	        }	        if (direction > 0) {	            this.executeMove(direction);	        }	    }	};
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
Well you should set the values to null not 0.

Also I think I was having that issue too, and that's probably why I put the condition check inside Scene_Map in the end and did something like:

Scene_Map.prototype.processMapTouch = function() { if ((TouchInput.isTriggered() || this._touchCount > 0) && $gamePlayer.canClick()) { // reset of stuff }}but you could probably alias it like:

Code:
var someAlias = stuffstuff;Scene_Map.prototype.processMapTouch = function() {  if ($gameTemp._menuButtonClicked) return;  someAlias.call(this);}
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Hmmm, it still moves one pixel depending on the direction. This is how I roughly translated your help:

Code:
	Game_Temp.prototype.setDestination = function(x, y) {		if ($gameTemp._menuButtonClicked) {		    this._destinationX = null;		    this._destinationY = null;		} else {		    this._destinationX = x;		    this._destinationY = y;		}	};	Game_Player.prototype.moveByInput = function() {	    if (!this.isMoving() && this.canMove()) {	        var direction = this.getInputDirection();	        if (direction > 0) {	            $gameTemp.clearDestination();	        } else if ($gameTemp.isDestinationValid()){	        	if (!$gameTemp._menuButtonClicked) {		            var x = $gameTemp.destinationX();		            var y = $gameTemp.destinationY();		            direction = this.findDirectionTo(x, y);	        	} else {	        		direction = this.findDirectionTo(null, null);	        		$gameTemp.clearDestination();	        	}	        }	        if (direction > 0) {	            this.executeMove(direction);	        }	    }	};		Scene_Map.prototype.processMapTouch = function() {	    if (TouchInput.isTriggered() || this._touchCount > 0) {	        if (TouchInput.isPressed()) {	            if (this._touchCount === 0 || this._touchCount >= 15) {	                var x = $gameMap.canvasToMapX(TouchInput.x);	                var y = $gameMap.canvasToMapY(TouchInput.y);	                if (!$gameTemp._menuButtonClicked) {						$gameTemp.setDestination(x, y);	                } else {	                	$gameTemp.setDestination(0, 0);	                }	            }	            this._touchCount++;	        } else {	            this._touchCount = 0;	        }	    }	};
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
You shouldn't need that Game_Player.prototype.moveByInput function since you have the scene map one.

Try this ones for the scene_map:

Scene_Map.prototype.processMapTouch = function() { if ((TouchInput.isTriggered() || this._touchCount > 0) && this._menuButtonClicked) { if (TouchInput.isPressed()) { if (this._touchCount === 0 || this._touchCount >= 15) { var x = $gameMap.canvasToMapX(TouchInput.x); var y = $gameMap.canvasToMapY(TouchInput.y); $gameTemp.setDestination(x, y); } this._touchCount++; } else { this._touchCount = 0; } }};That's the way it worked for me.

You also used "$gameTemp.setDestination(0, 0);" in the proccessMapTouch function which might be causing the move, instead you should not set anything or use $gameTemp.clearDestination();
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Okay, the character does not walk when clicked, but there is another problem. It seems I can't use the mouse tap now. 
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
You could have taken a look at how Dekita does it in his plugin: http://forums.rpgmakerweb.com/index.php?/topic/46944-dmv-map-buttons/

Specifically this part:

Code:
temp.setDestinationNotaButton = function(){    var bt, ix, iy;    var x = TouchInput.x;    var y = TouchInput.y;    var s = this.map_buttons.length;    for (var i = 0; i < s; i++){        bt = this.map_buttons[i];        ix = (x >= bt.x) && (x <= bt.x + bt.width);        iy = (y >= bt.y) && (y <= bt.y + bt.height);        if (ix && iy) {return false};    };    return true;};var setDest = temp.setDestination;temp.setDestination = function(x, y) {    if (this.setDestinationNotaButton()){        setDest.apply(this, arguments);    };};
"temp" is Game_Temp.prototype.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,975
Members
137,563
Latest member
cexojow
Top