moving shape
moving shape
(OP)
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
Thanks for any help.
Indo
RE: moving shape
'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
http://www.netian.com/~heesc
RE: moving shape
Indo