5 Replies - 491 Views - Last Post: 06 January 2019 - 07:09 AM Rate Topic: -----

#1 BeowuIf   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-September 18

Make an image bounce inside a shape

Posted 20 September 2018 - 06:25 AM

So im making a small game on vb6 and i need to make a small icon bounce around inside a box shape Posted Image

so i made this code on a timer and enabled it on my form load
 Private Sub Timer2_Timer()
    COUNTER = COUNTER + 1
    If Image2.Left <= Shape1.Left Then
        Image2.Left = Image2.Left + COUNTER * 1
        Else
        If Image2.Left >= Shape1.Left Then
            Image2.Left = Image2.Left - COUNTER * 1
        End If
    End If
    If Image2.Top <= Shape1.Top Then
        Image2.Top = Image2.Top + COUNTER * 1
        Else
        If Image2.Top >= Shape1.Top Then
            Image2.Top = Image2.Top - COUNTER * 1
        End If
    End If
End Sub 


but then this crazyness happen
Posted Image

can anyone please help me to make this work?

Is This A Good Question/Topic? 0
  • +

Replies To: Make an image bounce inside a shape

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15228
  • View blog
  • Posts: 60,973
  • Joined: 12-June 08

Re: Make an image bounce inside a shape

Posted 20 September 2018 - 06:38 AM

So the issue is top works to block, left works to block, but top left doesn't?
Was This Post Helpful? 0
  • +
  • -

#3 BeowuIf   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-September 18

Re: Make an image bounce inside a shape

Posted 20 September 2018 - 06:44 AM

View Postmodi123_1, on 20 September 2018 - 06:38 AM, said:

So the issue is top works to block, left works to block, but top left doesn't?


Yes, also @modi123_1 is there a way to make a ricochet like animation effect of the icon?
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 979
  • View blog
  • Posts: 3,858
  • Joined: 13-June 14

Re: Make an image bounce inside a shape

Posted 20 September 2018 - 06:54 AM

Of course there is. Change the sign of the relevant velocity components when the object reaches the wall.
Was This Post Helpful? 1
  • +
  • -

#5 BeowuIf   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-September 18

Re: Make an image bounce inside a shape

Posted 20 September 2018 - 12:18 PM

View Postndc85430, on 20 September 2018 - 06:54 AM, said:

Of course there is. Change the sign of the relevant velocity components when the object reaches the wall.

your tip helped me solve it ty
Posted Image
Was This Post Helpful? 0
  • +
  • -

#6 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 979
  • View blog
  • Posts: 3,858
  • Joined: 13-June 14

Re: Make an image bounce inside a shape

Posted 06 January 2019 - 07:09 AM

It makes sense if you remember the conservation of linear momentum (assuming an elastic collision and that the wall doesn't move) ;).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1