Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 13th, 2007, 03:16 AM
Registered User
 
Join Date: Sep 2006
Location: , , United Kingdom.
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?

Thanks
Reply With Quote
  #2 (permalink)  
Old February 13th, 2007, 09:58 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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

http://msikes.spaces.live.com/Blog/

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:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
Reply With Quote
  #3 (permalink)  
Old February 13th, 2007, 10:23 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

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:

    http://www.vb-helper.com/howto_net_bouncing_ball.html

Rod

Rod
RodStephens@vb-helper.com
Author of "Visual Basic 2005 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref.htm

Sign up for the free VB Helper Newsletters at http://www.vb-helper.com/newsletter.html
Reply With Quote
  #4 (permalink)  
Old February 13th, 2007, 05:22 PM
Registered User
 
Join Date: Sep 2006
Location: , , United Kingdom.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 01:35 PM
drawing fergo BOOK: Access 2003 VBA Programmer's Reference 1 June 5th, 2005 10:32 AM
Drawing in C# stripytiger VS.NET 2002/2003 4 August 25th, 2004 11:01 AM
drawing with VBA cutovoi Excel VBA 1 February 19th, 2004 07:22 PM



All times are GMT -4. The time now is 05:37 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.