Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving shape 1

Status
Not open for further replies.

INDO

Programmer
Mar 18, 2001
12
0
0
US
I am trying to get a shape to move by using a timer and 4 buttons. The idea is to get the timer to get the shape moving to the right on creation and then use the buttons to move the shape either to the left, up or down. The problem is that when the form is created and the shape begins to move, if I click on down for example the shape will move down however it then reverts to moving right again. How can I stop this so the shape moves only in the direction I wish.

Thanks for any help.

Indo
 
Maybe you defined two coordinates to move the shape, i.e.
'x' and 'y'. And now we can define increment for each
directions by defining 'dx' and 'dy'.

Now we have,
int x=INITIAL_X, y=INITIAL_Y, dx=1, dy=0;

1. Assume INITIAL_X and INITIAL_Y are predefined constant.
I assumed dx=1 because you said the shape moves to right
direction initially.

2. Assume screen coordinates system, which means the
direction of y axis is down.

3. The pseudo code to move shape will be :
up button event : dx=0; dy=-1;
down button event : dx=0; dy=1;
right button event : dx=1; dy = 0;
left button event : dx=-1; dy=0;

4. Now you can write your timer code to move your shape.
x += dx;
y += dy;

5. You need to check the shape is in the visible area
to prevent it is disappeared from sight.

6. And it is possible to control the velocity of moving shape.
For example, if dx=2, the shape moves more faster than
dx=1.

It is also possible to move the shape diagonally.
Hee S. Chung
heesc@netian.com
 
Thanks alot greatkingrat that was very helpful.

Indo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top