|
-
Jun 8th, 2001, 02:07 PM
#1
Thread Starter
Addicted Member
A problem from a beginner!!
I just want to , for example, move a ball or an object in a pictureBox, randomly, and make it rebound on the "wall" of the picturebox.
What api function should I use ? .. how?
-
Jun 8th, 2001, 02:56 PM
#2
New Member
There are times when you should use the API, and times you shouldn't. It's a toolbox of sorts, and is kind of like having an automatic screwdriver. By this I mean, you can do without it just fine, but usually for larger projects, or if you don't have a large amount of time to research the several methods to accomplish a simple function (- that the API |CAN| do), it works fine.
Using that poor analogy of mine, I would suggest learning how to use the screwdriver manually first. To make a ball move around a form, if you use a picturebox, try using a timer. Timer's repeat code according to an interval. Set this interval, and thats how many time your code will repeat.
The trick is, x=X+int, y =Y+int (int is either +1 for positive motion, -1 for negative -- yeah i think that should work), this will move your ball in a perfectly diagonal motion. Now to keep it on the screen, make sure you have a loopback statement, i.e
If X = 630 (assuming the form is 640 pixels wide and the picture box is 10 (remember x and y coords are taken from the top left of the box if i am not mistaken) then int = -1 (now the ball will start going backwards), now you need one for the 0 side, so If X = 0 then int = +1, now the ball starts going the other way!
The y coordinate is the same idea. Now remember this will only make a ball bounce from corner to corner, to get it randomly bouncing, you will have to vary the int value, so that your rate of ascent and descent (movement) isn't perfectly diagonal,
hope this helped somewhat!
csnow
Last edited by csnow; Jun 8th, 2001 at 03:00 PM.
csnow
-
Jun 8th, 2001, 03:14 PM
#3
Thread Starter
Addicted Member
thanks for the tip!
I'll try something with this
-
Jun 8th, 2001, 03:59 PM
#4
There a VB demo that does this, as well as some other "Timer" demos. The believe the project name is called "Blanker"
-
Jun 8th, 2001, 08:57 PM
#5
Use the "ScaleWidth" and "ScaleHeight" properties of the picturebox. They measure only the inside of the picture box, not including the border.
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|