Looking for VB function to bounce graphic around screen - Please 
Author Message
 Looking for VB function to bounce graphic around screen - Please

Is there a formula or book somewhere that might explain how to bounce an
object around the screen where, when it hits the corners or edges it will
bounce back. I have figured out all my own drawing functions I needed by this
one still puzzles me.

Thanks for you help

Michael Gernaey



Mon, 03 Nov 1997 03:00:00 GMT  
 Looking for VB function to bounce graphic around screen - Please

Quote:
> Is there a formula or book somewhere that might explain how to bounce an
> object around the screen where, when it hits the corners or edges it will
> bounce back. I have figured out all my own drawing functions I needed by this
> one still puzzles me.

Assuming your using a timer to move your objects:

Sub Timer1()

const AmountToMove = 50
Static MoveRight as integer  'boolean
Dim WhichWay as integer

If MoveRight THen    
   'check to see if hit right side of screen.
   If object1.Left + object1.width >= Screen.Width  Then
      WhichWay = -1  'move left
      MoveRight = False
   Else
      WhichWay = 1
      MoveRight = True
   End If
Else    'it is moving left
   'check if hit left side of screen
   If object1.Left <= 0 Then
      WhichWay = 1  'positive to the right now
      MoveRight = True
   Else
      WhichWay = -1
      MoveRight = False
   End If
End If

'move the object
object1.Left = object1.Left - (WhichWay * AmountToMove)

This is off the top of my head, you'll have to test it out.  The best
approach would be to put it into a procedure, and pass the object you
are moving(assuming it is a control of some kind) to the procedure.

Sub MoveX (Source as Control)   'souce is a picture or image box
'above code
Similar for movement in Y direction, just remember the top of the
screen is 0, and you increase Y as you go down the screen.  This
always screws me up for a bit.
Goodluck.    
----------------------------------------------------------------------
Greg Carter
Fourth Year Electrical Engineering
Carleton University
Ottawa, Ontario, Canada


Take a look at my home page on the
World Wide Web: http://chat.carleton.ca/~gcarter
----------------------------------------------------------------------



Wed, 05 Nov 1997 03:00:00 GMT  
 Looking for VB function to bounce graphic around screen - Please

Quote:


> > Is there a formula or book somewhere that might explain how to bounce an
> > object around the screen where, when it hits the corners or edges it will
> > bounce back. I have figured out all my own drawing functions I needed by this
> > one still puzzles me.

[Code to move object delected]

Quote:
> 'move the object
> object1.Left = object1.Left - (WhichWay * AmountToMove)

Looking over this it should read

  object1.Left = object1.Left + (WhichWay * AmountToMove)

Michael,  Did this code work?
----------------------------------------------------------------------
Greg Carter
Fourth Year Electrical Engineering
Carleton University
Ottawa, Ontario, Canada


Take a look at my home page on the
World Wide Web: http://chat.carleton.ca/~gcarter
----------------------------------------------------------------------



Thu, 06 Nov 1997 03:00:00 GMT  
 Looking for VB function to bounce graphic around screen - Please

Quote:


>Subject: Re: Looking for VB function to bounce graphic around screen - Please
>Date: Sun, 21 May 1995 20:15:55 GMT


>> > Is there a formula or book somewhere that might explain how to bounce an
>> > object around the screen where, when it hits the corners or edges it will
>> > bounce back. I have figured out all my own drawing functions I needed by
>this
>> > one still puzzles me.
>[Code to move object delected]
>> 'move the object
>> object1.Left = object1.Left - (WhichWay * AmountToMove)
>Looking over this it should read
>  object1.Left = object1.Left + (WhichWay * AmountToMove)
>Michael,  Did this code work?
>----------------------------------------------------------------------
>Greg Carter
>Fourth Year Electrical Engineering
>Carleton University
>Ottawa, Ontario, Canada

>Take a look at my home page on the
>World Wide Web: http://chat.carleton.ca/~gcarter
>----------------------------------------------------------------------

Well the only problem is that when I reach a point where going any farther
there needed to be a check on which variable would become ( - ) and have it
start to move in the opposite direction. With the help of many people I have
figured it out. Actually although I appreciate the great help by everyone who
answered because many did with the right answer, I found it (because of
someone else's suggestion) in the SAMPLE VB program Blanker..

Thanks to everyone who answered, my project is finished and I owe it to all
you VB friends out there :)

Michael Gernaey



Thu, 06 Nov 1997 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. bouncing graphics in VB

2. Please Help:Looking for DIGAMMA Function for VB

3. Help -- Trying to get around VB's lack of graphics capabilities

4. Screen Graphics Help... Please

5. How can I make an object 'bounce' around screen?

6. Small VB graphic Demo (Look at this) - vbgdemo.zip (1/1)

7. Looking for VB Graphics Source - Help

8. Looking for VB Graphics Source - Help

9. Looking for VB Graphics Source - Help

10. Looking for VB Graphics Source - Help

11. Looking for VB Graphics Source - Help

12. Full screen graphics with VB 4 Standard

 

 
Powered by phpBB® Forum Software