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

2014/11/2

Need help with "move" speed

Oldmoe Oldmoe

2014/11/2

#
So I'm a little confused with how my "move" code is working in the code below.
1
2
3
4
5
6
7
8
public void moveUp()
     {
            setLocation(getX(), getY()-1);
                   if (Greenfoot.isKeyDown("w"))
                              {
                                 setLocation(getX(), getY()+6);
                               }
    }
It is from a scrolling style game that moves from bottom to top. What was supposed to happen was as you hit run the ship starts moving up the screen, when you hit the "w", the ship would slow down. Although it works, something I've done in the code has caused a weird reaction. In the line setLocation(getX(), getY()-1);, if getY was "0" it should be stationary. However "+4" makes it stationary, "0" moves quite fast and "+1" through "+3" continue to move up instead of down. The entire program was posted if you want to see the rest of the code. IT's called "Need help with my "move" issues"
danpost danpost

2014/11/2

#
Your problem is due to the fact that your 'moveLeft' and 'moveRight' methods, which are called every act cycle, each move your ship up the screen 2 pixels, netting 4 pixels up per act. Remove those calls from the 'act' method; and then remove the adjustment line of '+6' you added. Actually, should your TestShip object be influenced at all by the movement of the MyShip object? I would think not; that is, you should not even ask if the "w" key was down in the TestShip class. Or was that part of the scrolling effect? If so, the amount of movement should be equivalent to that of the movement of the Space object.
Oldmoe Oldmoe

2014/11/2

#
Thanks, the TestShip was a new class originally extended from "vehicle" class that had the movement controls, when I created the new "TestShip" it extended from the Actor and I merged the movement controls over. Couldn't figure it out for the anything. This is part of a bigger piece and there are multiple actors doing things, so the "w" tie in was to cause the TestShip to adjust speed as MyShip moved. Thanks again
danpost danpost

2014/11/2

#
Oldmoe wrote...
This is part of a bigger piece and there are multiple actors doing things, so the "w" tie in was to cause the TestShip to adjust speed as MyShip moved. Thanks again
You have movement due to the "w" key added to the TestShip class; however, it does not match the amount of movement with the Space class. I believe, since that is scrolling movement, the amounts should match and you should also check for and adjust the TestShip objects location on the "s" key also. Regards.
You need to login to post a reply.