Wrox Programmer Forums
BOOK: Visual Basic 2005 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2005 Programmer's Reference by Rod Stephens; ISBN: 9780764571985
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2005 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 13th, 2007, 03:16 AM
Registered User
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default drawing method

I was trying to make a bouncing circle program,I hope if the circle reach the edge of the form, it will bounce back, I used the following coding:
if X+100 >= me.with then,
x = me.with -100
if y+100 >= me.height then
y = me.height-100

However, it seems the circle is still drawn have in form, half off the form,

Could anybody tell me why please?

Old February 13th, 2007, 09:58 AM
Wrox Author
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

The alogorithim for this isn't that simplistic. I have done something similar using the XNA framework but can't remember the exact alogoritihim.


that link is an XNA resource, ignore all of the Draw and Update code and focus on the calculations that are preformed about half way down through the source.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
Old February 13th, 2007, 10:23 AM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

What is the diameter of the circle? If it's greater than 100, then it would stick off the edge of the form sometimes.

Usually I just reverse the direction of movement and don't worry if the ball moves a little off the screen. See this example:



Author of "Visual Basic 2005 Programmer's Reference"

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
Old February 13th, 2007, 05:22 PM
Registered User
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

It works! Thanks for all your help. After reading Mr Stephen's bouncing ball example, I used Me.ClientSize.Width and Me.ClientSize.height for checking the boundary, it works perfect.
 I used me.width and me.height before, it returns a slightly bigger value than client size, and therefore the ball always slips half outside the screen.

Thanks again

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing Shapes cbulutlar Javascript 2 March 6th, 2006 02:25 PM
drawing fergo Access VBA 0 June 6th, 2005 12:35 PM
drawing fergo BOOK: Access 2003 VBA Programmer's Reference 1 June 5th, 2005 09:32 AM
Drawing in C# stripytiger VS.NET 2002/2003 4 August 25th, 2004 10:01 AM
drawing with VBA cutovoi Excel VBA 1 February 19th, 2004 07:22 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.