borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (looping dts)Next Topic (On Which File Should I Run Regsvr32?) New Topic New Poll Post Reply
AndreaVB Forum : VB General : collision detection help Solved Topic
Poster Message
duval
Level: Protégé

Registered: 06-10-2006
Posts: 5

icon collision detection help

thank you for helping me in my last question this forum is awesome,

now I have another puzzling request (at least for me )


i am trying to move the my square left and right with my mouse but i do not want it to go out of the screen, i have tried many views to approaching my problem and my best results where as follows,

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Square.Left = X '- Square.Width

End Sub


this prevents it from going left but it infinitely can go right, while adding the code '- Square.width' prevents it from going right but infinitely goes left

please help my over all goal is to make the square movable only within the form

____________________________
Chaos = Multiverse = Us.

07-10-2006 at 01:47 AM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: collision detection help

Hi,
This is called boundary (or bounds) checking.
Compute the new location - without moving the item, then limit it to a given set of values. Finally move the item.

Example:
dim sq_new_x as long

sq_new_x = x
if sq_new_x > me.scalewidth then sq_new_x = me.scalewidth
if sq_new_x < 0 then sq_new_x = 0

me.square.left = sq_new_x


Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

08-10-2006 at 05:42 PM
View Profile Send Email to User Show All Posts | Quote Reply
duval
Level: Protégé

Registered: 06-10-2006
Posts: 5
icon Re: collision detection help

Thank you very much this is a good piece of code to learn from, like always you guys are awesome, I have found that with this code it still leaves to the right but by adding - square.Width it stops from leaving

dim sq_new_x as long

sq_new_x = x

if sq_new_x > me.scalewidth - square.width then sq_new_x = me.scalewidth - square.width

if sq_new_x < 0 then sq_new_x = 0

me.square.left = sq_new_x

____________________________
Chaos = Multiverse = Us.

08-10-2006 at 09:48 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: collision detection help

Glad to help.


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

09-10-2006 at 09:30 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : collision detection help Solved Topic
Previous Topic (looping dts)Next Topic (On Which File Should I Run Regsvr32?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder