Click to See Complete Forum and Search --> : moving graphics
MPrestonf12
Aug 13th, 2000, 12:16 PM
Does anyone know how to move a object like a picturebox around the screen in a smooth line. I tried making it move ramdomly but obviously that doesn't work. Any suggestion are appreciated. Thanks
V(ery) Basic
Aug 13th, 2000, 12:52 PM
Couldn't you just BitBlt it to the form's hDC, chnaging the X coords every loop?
If this isn't what you wanted...
Private Sub cmdError_Click()
Dim MyRnd as Integer
Randomize
MyRnd = CInt(Rnd * 1)
Form1.Print IIf(MyRnd, "Bite Me", "I'm Sorry")
End Sub
:rolleyes: must ne the LSD again :rolleyes:
MPrestonf12
Aug 13th, 2000, 02:19 PM
yes, but you can't randomly change the X cordinate or it will just jump around the screen..thanks for the code
Sam Finch
Aug 13th, 2000, 02:36 PM
OK what you want is some sub to work out the X and Y coordinates when given a time. Say you want it to move in a circle you could have a function like this
Private Sub SetXY(ByRef X as Single, ByRef Y As Single, ByVal T As Double)
X = 1000 + (100 * Sin(T))
Y = 1000 + (100 * Cos(T))
End Sub
Then do something like this
Dim T As Double
Dim x As Single
Dim y As Single
T = Timer
Do
Call SetXY(x, y, Timer - T)
Picture1.Move x, y
DoEvents
Loop
and as if by majic the picture moves in a circle really slowly.
as long as you can work out a function for where you want the picturebox to go then you can move it in any way you like
Fox
Aug 13th, 2000, 03:24 PM
I think he wants to move it, not especially in a circle.. try this:
(Add a command button to an empty
project and add the whole code here)
'Declares
Private Declare Function GetTickCount Lib "kernel32" () As Long
'Variables
Dim Active As Boolean
Sub MoveObject(Target As Object, Optional Pause As Long = 0, Optional Speed As Single = 1)
Dim NextTick As Long
Dim X As Single
Dim Y As Single
Dim Dest As Single
'Variables
X = Target.Left
Y = Target.Top
Randomize
'Main loop
Active = True
While Active
'Timer
If NextTick <= GetTickCount Then
NextTick = GetTickCount + Pause
'Move target
X = X + Sin(Dest) * Speed
Y = Y + Cos(Dest) * Speed
Dest = Dest + ((100 * Rnd) - 50) / 1000
Target.Move X, Y
End If
DoEvents
Wend
End Sub
Private Sub Command1_Click()
MoveObject Command1
Command1.Enabled = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Active = False
End
End Sub
(If you set ScaleMode of the Form to pixel
it probably moves too fast, if so change the
speed or wait arguments as you wish...)
[Edited by Fox on 08-13-2000 at 04:26 PM]
MPrestonf12
Aug 13th, 2000, 06:20 PM
great! thaks for the code
V(ery) Basic
Aug 14th, 2000, 06:45 AM
PS The code sample I posted had nothing to do with the code I was suggesting. It was kind of a joke.
Look at it like this:
If Not(WhatWanted) Then
Dim MyRnd as Integer
Randomize
MyRnd = CInt(Rnd * 1)
Form1.Print IIf(MyRnd, "Bite Me", "I'm Sorry")
End If
That means that if the idea of BitBlting it to the Form's hDC was not what you wanted then WhatWanted would equal false causing the IIf structure to fire. That would either return "Bite Me" (as in aggressive) or "I'm Sorry" (as in submissive).
I was talking to you in VB rather than in English.
Sorry for the misunderstanding, however:
MPrestonf12
Aug 14th, 2000, 11:10 AM
I knew your code had nothing to do with it.But I still got a laugh out of it
Sam Finch
Aug 14th, 2000, 11:38 AM
Private Sub cmdError_Click()
Dim MyRnd as Integer
Randomize
MyRnd = CInt(Rnd * 1)
Form1.Print IIf(MyRnd, "That was funny", "You Suck")
End Sub
you'll notice I've changed t just enough to avoid copyrite problems
Mad Compie
Aug 15th, 2000, 02:54 AM
For really really SMOOTH scrolling pictures around your desktop you can use "Pegasus SuiteFace v2.1". This soft contains some OCX to do the scrolling (and some other interesting FX).
You'll also be able to move pictures with a transparent background at high speed!
This package is really interesting because it's easy to implement in your VB projects and does not require a lot of code.
If you would achieve the same result with Blt at high speed, a lot of coding would be required!
You can find the tool at http://www.pegasustools.com.
Also many cracks are available on the net.
royjacob
Aug 16th, 2000, 10:32 AM
The easiest way to move a picturebox ina straight line is to chang PictureBox's coordinates every second. All you have to do is to insert a Timer Object onto the form. the code is as follows
Sub Timer1_Timer()
Picture1.Left = Picture1.Left + 120
'Say that the X coordinate of the farthest point of the
'form is 4440. Then we want it to stop
If Picture1.Left = 4440 Then
Timer1.Enabled = False
End If
End Sub
MPrestonf12
Aug 16th, 2000, 02:36 PM
First of I just wanted to make it stop but this code in thoery should work but doesn't!
picball.Left = picball.Left + 12
If picball.Left <= Form1.Width Then
Timer1.Enabled = False
End If
Fox
Aug 16th, 2000, 03:35 PM
Try this:
picball.Left = picball.Left + 12
If picball.Left + picball.width > Form1.Width Then
Timer1.Enabled = False
End If
royjacob
Aug 17th, 2000, 09:40 PM
I think I know what your problem is. I made the mistake by telling you to compare the Picture Box's 'Left' Property with the Form's 'Width' Property. Well what you should do is, during design time, manually drag the picture box to the point in the form where you want it to stop. If you keep pressing the mouse button down, you will notice that that the Picture Box's 'Left' and 'Top' Values will be displayed. Use the 'Left' Value displayed as the value at which the Timer should be disabled.
Mad Compie
Aug 18th, 2000, 02:18 PM
Consider also using a For...Next loop with the DoEvents Method to move your graphics VERY FAST, instead of a Timer Control.
Also take a look at Pegasus SuiteFace (as mentioned above). With this OCX you can even move transparent graphics at high color VERY VERY FAST and SMOOTH...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.