Results 1 to 6 of 6

Thread: Move Image slowly across the form

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Exclamation Move Image slowly across the form

    I want to make a game for my baby brother and i want to have an image of the cookie monster move across the screen three time to a cookie that he will take and that will be the scoring mechanism. I only now how to make him appear and then jump to the cookie but now how to have him pause in the middle. Any help will be greatly appreciated.

  2. #2
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Move Image slowly across the form

    How do you do it now? Rather than reinventing the wheel for you, show us your current method and we can go from there.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Re: Move Image slowly across the form

    Code:
    Option Explicit
    Private Sub Command2_Click()
    If txtA1.Text = "Blue" Then
    MsgBox ("You are right")
    Else
    MsgBox ("Uh-oh! Cookiemoster takes a cookie Urum num num num")
    Image2.Visible = True
    End If
    If txtA2.Text = 2 Then
    MsgBox ("You are right")
    Else
    MsgBox ("Uh-oh! Cookiemoster takes a cookie Urum num num num")
    End If
    End Sub
    
    Private Sub Timer1_Timer()
    Image2.Left = Image2.Left - 500
    If Image2.Left < 2880 Then
        Timer1.Enabled = False
    End If
    If Image2.Left = 2880 Then
            Image1.Left = Image1.Left - 500
            End If
    End Sub
    This all my code so far?

  4. #4
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Move Image slowly across the form

    Frankly, your code is a garbled mess, and I can't make out entirely what you are trying to do. That said, a few minor changes should get you what you need, and I love the theme of the program. Here's a quick little bit of code that moves an image control across a form in a figure-eight pattern that uses the same technique that you are trying to do. All you need is an Image, a Timer, a Command button, and a large enough form to get this to run.

    This should be a solid enough example to show you how you can move an image across the screen. Now it is up to you to figure out how to move the Cookie Monster along the path that you want. Good luck!

    Code:
    Option Explicit
    
    Private m_Interval As Long
    Private m_Flip As Long
    
    Private Const TOTAL_INTERVALS As Long = 360
    Private Const XORIGIN As Long = 5000
    Private Const YORIGIN As Long = 5000
    Private Const RADIUS = 1000
    Private Const TIMER_INTERVAL As Long = 10
    
    Private Sub Command1_Click()
        m_Interval = 0
        Timer1.Interval = TIMER_INTERVAL
        Timer1.Enabled = True
        m_Flip = 1
    End Sub
    
    Private Sub Timer1_Timer()
        Dim x As Long, y As Long
        Dim a As Double
        
        m_Interval = (m_Interval + 1) Mod TOTAL_INTERVALS
        If m_Interval = 0 Then m_Flip = m_Flip * -1
        a = m_Interval * 6.28318530717959 / TOTAL_INTERVALS
        x = (m_Flip * (RADIUS * (1 - Cos(a))))
        y = RADIUS * Sin(a)
        
        Image1.Visible = False
        Image1.Left = XORIGIN + x
        Image1.Top = YORIGIN + y
        Image1.Visible = True
    End Sub
    Note: I make no claim that this is the best way to do this, but I wanted to model the approach after the OP's example.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    8

    Re: Move Image slowly across the form

    Op??

  6. #6
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Move Image slowly across the form

    OP can refer to "original post" or "original poster" interchangeably. In my post, I meant OP to refer to original poster, aka you.

Tags for this Thread

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