Searched the forums but didn't find what I was looking for. Is there a way to have the player to walk always when the left mouse button is pressed. This came to mind first to try "if (mouse.IsButtonDown(eMouseLeft)) {
cEgo.Walk(mouse.x, mouse.y, eNoBlock, eWalkableAreas);
}" but he won't move until i release the button. Is there a way to make this work? most of the rooms I'm making are scrolling so it would be a little more comfortable if you could walk without having to click every 2 seconds (lazy ass I know) ;D
Without testing it you could try something like this:
function repeatedly_execute()
{
if (mouse.IsButtonDown(eMouseLeft))
{
if (!player.Moving)
{
int x = mouse.x - (player.x - GetViewportX());
if (x >= 0) x = Room.Width; // mouse was clicked at or to the right of player, walk to the right
else x = 0; // mouse was clicked to left of player, walk to the left
player.Walk(x, mouse.y, eNoBlock, eWalkableAreas);
}
}
else if (player.Moving) player.StopMoving();
}
You'd probably want some other conditions added into that. Also, not sure if it was intended, but with this the player wouldn't follow the mouse, just continue moving in whatever direction he first set out in.
Thanks! but still the same problem. he just stands still having seizures until i release the mousebutton hehe!
Like monkey said, this code won't work with a held down mouse button.
What it does is it'll make the player walk further than the click.
Ah yeah...I completely forgot what he said there hehe...but that's not bad either though! I'm gonna try this again! I tried it and left/right works but when it comes to up,down it won't work...I played around a little but eventually it just crashed the game :(
Wouldn't it be possible to use a boolean value to check whether the player has already been told to walk left/right, which only needs to be changed when the mouse changes from left to right or the mouse is no longer held. That should stop the player from spazzing out when the mouse button is held... something like:
//at the top
bool ToldToMove = false; //Checking Whether the player has been told to move
bool MovingRight = false; //Checking the direction the player is moving in
//then:
function repeatedly_execute()
{
if (mouse.IsButtonDown(eMouseLeft))
{
if (!player.Moving)
{
int x = mouse.x - (player.x - GetViewportX());
if (x >= 0)
{
x = Room.Width; // mouse was clicked at or to the right of player, walk to the right.
if(!MovingRight)
{
MovingRight == true;
ToldToMove = false; //to reset the walkpath
}
}
else
{
x = 0; // mouse was clicked to left of player, walk to the left
if(MovingRight)
{
MovingRight == false;
ToldToMove = false; //to reset the walkpath
}
}
if(ToldToMove == false)
{
player.Walk(x, mouse.y, eNoBlock, eWalkableAreas);
ToldToMove = true;
}
}
}
else if (player.Moving)
{
player.StopMoving();
ToldToMove = false;
}
}
This is untested as I am away from home, but see if that works... You can of course replace the boolean MovingRight with a loop check but I cannot for the life of me remember which loop counts for what direction :P
Obviously this code doesn't account for the y parameter, but I'm not sure if this code is fully functional yet...I'm sure it's implementanal.
Hope that helps!
Well...left and right works...but I had to remove the "MovingRight == true;" on line 17 and on line 26. That generated an parse errormessage. Up and down would be nice too since the character has 8 direction movement :) Thx so far!!!