DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005
    Posts
    1

    Simple animation with VB6.0

    I am trying to make a basic screensaver in VB6.0. All I need to know is how to make an image bounce around the screen randomly like many Windows based screensavers. This is for a project I am doing for myself. I AM a total beginner at programming. Please help. Thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2005
    Posts
    103
    you could do it vb helper's way or you can use a DoLoop and randomly throw a picturebox all over the place also. I haven't tested it, but it should work. All you need is a command button and a picturebox

    Code:
          Dim GetScreenHeight As Integer, GetScreenWidth As Integer 'Screen
    Dim CurrentXPos As Long, CurrentYPos As Long, RandomX As Long, RandomY As Long 'X&Y Values
    Private Sub cmdAnimation_Click()
    If frmMain.WindowState = 2 Then 'incase if Form was maximized already then set to Normal
    'or it will cause error
            WindowState = 1
    End If
          GetScreenHeight% = Screen.Height
          GetScreenWidth% = Screen.Width
    If cmdAnimation.CausesValidation = True Then
                frmMain.Height = GetScreenHeight% 'Set Y
                    frmMain.Width = GetScreenWidth% 'Set X
                            RunScreenSaver
                                moveRandom = 1
        End If
    End Sub
    
    Private Function RunScreenSaver()
    Dim moveRandom As Integer
    PicBox.Visible = True 'Set Default as False to show it at a later time
    Do 'Start Repeat
        Randomize 'Initializes Random-Generator | rnd() |
        
            CurrentXPos& = PicBox.Left 'Get X
                CurrentYPos& = PicBox.Top 'Get Y
    
    RandomX& = CurrentXPos& + Rnd(10)
    RandomY& = CurrentYPos& + Rnd(10)
                
         PicBox.Move RandomX&, RandomY&
                If moveRandom% > 19999 Then
                                        moveRandom% = 0
                                    RandomX& = Rnd(1000)
                            End If
                        If Me.Width < RandomX& - 200 Then
                    PicBox.Move Rnd() * ScaleWidth, Rnd() * ScaleHeight 'Blow-Back effect randomly across screen
            End If
                    If Me.Height < RandomY& - 200 Then
                            PicBox.Move Rnd() * ScaleWidth, Rnd() * ScaleHeight 'Blow-Back effect randomly across screen
            End If
                DoEvents 'Yield
                        moveRandom% = moveRandom% + 1
                        WindowState = 2
    Loop 'Repeat
    End Function

Similar Threads

  1. Creating a Simple Combo Box in a Web App
    By Ranchoz71 in forum ASP.NET
    Replies: 3
    Last Post: 04-06-2005, 12:40 PM
  2. Simple VB 6.0 XML parsing
    By slimasian in forum VB Classic
    Replies: 1
    Last Post: 03-02-2005, 01:38 PM
  3. Layer animation problems
    By MusoSpuso in forum Web
    Replies: 1
    Last Post: 06-12-2002, 02:11 AM
  4. Animation Control question
    By treeve moss in forum VB Classic
    Replies: 2
    Last Post: 05-05-2000, 01:44 AM
  5. Animation Control question
    By treeve moss in forum VB Classic
    Replies: 0
    Last Post: 05-04-2000, 05:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links