This site requires JavaScript, please enable it in your browser!
Greenfoot back
ZekeroXBlade
ZekeroXBlade wrote ...

2013/3/11

Slow down moving speed

ZekeroXBlade ZekeroXBlade

2013/3/11

#
Hi, I'm a noob at coding and was wondering if anyone can help me with my issue. I am trying to create an RPG type game but I need help with walking slower. I read the tutorials provided here and learned the move code, but I want to have it so I move one cell per second when holding the arrow key. Sorry if I'm not describing my issue very well but here is the link to the game http://www.greenfoot.org/scenarios/7660
-nic- -nic-

2013/3/11

#
you can do a number of things depending on how you are deciding to go about this you can: import the smoothMover class which allows you too move in amounts than less thank one e.g. 0.5 etc do this by going to edit (in the normal enviroment and then import class then pressing import if smoothMover is selected) then in the class you want to move change the extends code to
public class "name of your class here" extends SmoothMover
and then putting:
move(0.1);
or whetever you need or you could create a timer:
if(timer<0)//test to see if enough time has passed 
{
timer=10;//reset the timer
move(1)//move
}
else//not able to move
{
timer--;//make timer smaller if not moved
}
ZekeroXBlade ZekeroXBlade

2013/3/11

#
Thank you for the help, and sorry for the late response, but I'm having trouble with moving on the y axis. I use the code
if (Greenfoot.isKeyDown("up"))
{
setLocation(getX(), getY()-1);
}
to move up and when I try to change the -1 to -0.1, my character does not move at all. I also tried the timer, but Greenfoot says "cannot find symbol - variable timer" Thank you for helping me get some done!
-nic- -nic-

2013/3/11

#
sorry if you were to use the timer method you would need to create a int where all the other varibles are
public int timer=10;

methods down here
using 0.1 might not be enough for it to actually move try using -0.2 or -0.3
ZekeroXBlade ZekeroXBlade

2013/3/11

#
Thanks for the help! Finally got it to work ^-^
-nic- -nic-

2013/3/12

#
cool
You need to login to post a reply.