×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

moving shape

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

RE: moving shape

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
http://www.netian.com/~heesc

RE: moving shape

(OP)
Thanks alot greatkingrat that was very helpful.

Indo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close