Results 1 to 15 of 15

Thread: moving graphics

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    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
    Matt

  2. #2
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Question

    Couldn't you just BitBlt it to the form's hDC, chnaging the X coords every loop?

    If this isn't what you wanted...

    Code:
    Private Sub cmdError_Click()
    
    Dim MyRnd as Integer
    
    Randomize
    
    MyRnd = CInt(Rnd * 1)
    
    Form1.Print IIf(MyRnd, "Bite Me", "I'm Sorry")
    
    End Sub
    must ne the LSD again
    Courgettes.

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    yes, but you can't randomly change the X cordinate or it will just jump around the screen..thanks for the code
    Matt

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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

    Code:
     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

    Code:
    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



  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    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)

    Code:
    '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]

  6. #6

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    great! thaks for the code
    Matt

  7. #7
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    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:

    Code:
    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:


    Courgettes.

  8. #8

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Smile

    I knew your code had nothing to do with it.But I still got a laugh out of it
    Matt

  9. #9
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Code:
    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

  10. #10
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Lightbulb

    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.

  11. #11
    Lively Member
    Join Date
    Aug 2000
    Posts
    117

    Thumbs down

    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

  12. #12

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Unhappy

    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
    Matt

  13. #13
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Try this:

    Code:
    picball.Left = picball.Left + 12 
    If picball.Left + picball.width > Form1.Width Then 
        Timer1.Enabled = False 
    End If

  14. #14
    Lively Member
    Join Date
    Aug 2000
    Posts
    117
    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.

  15. #15
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width