Game Boundaries
Game Boundaries
Game Boundaries
Game Boundaries
Game Boundaries
Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries
Game Boundaries Game Boundaries
Game Boundaries
Go Back  Xtreme Visual Basic Talk > > > Game Boundaries


Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2010, 04:18 AM
WooKie WooKie is offline
Newcomer
 
Join Date: Dec 2010
Posts: 2
Default Game Boundaries


Hi, sorry if i've posted this in the wrong section but basically i have a moveable character (image2) which I placed in a rectangle (shape1), I want it to stay in the box and created a left boundaries which the code is below, I've spent many hours trying to work out a code for the right side but i'm having alot of trouble, can anyone help me please.
Thank you.
Code:
If Image2.Left <= Shape1.Left Then Image2.Left = Shape1.Left
Reply With Quote
  #2  
Old 12-13-2010, 04:39 AM
wolfstrike's Avatar
wolfstrike wolfstrike is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 336
Default

why don't you just make the .Left of each item the same value when you make a move?
__________________
The Pho·net·ic Programmer
Reply With Quote
  #3  
Old 12-14-2010, 09:54 AM
passel's Avatar
passelGame Boundaries passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Just reverse the direction of the compare, >= instead of <=, and use the right side of the controls. The right side of Image2 would be Image2.Left + Image2.Width.
I assume you can figure how to calculate the right side of Shape1.

The only "tricky" part is that to keep the image inside the right side of the shape you have to set the .Left property to some value, so what would you set the Image2.Left property to, to keep the image inside the right side of the Shape?




A. Image2.Left = ShapeRight - Image2.Width
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #4  
Old 12-20-2010, 02:27 AM
WooKie WooKie is offline
Newcomer
 
Join Date: Dec 2010
Posts: 2
Default

Sorry i took my time replying, but thank you for the help and fast reply guys.
EDIT:
I tried this but the code I figured out didn't work, can you guys push me in the right direction from this
Code:
If (Image2.Left + Image2.Width) >= Shape1.Left Then (Image2.Left + Image2.Width) = Shape1.Left

Last edited by WooKie; 12-20-2010 at 02:35 AM.
Reply With Quote
  #5  
Old 12-20-2010, 08:49 AM
passel's Avatar
passelGame Boundaries passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I assume you want to keep it in from the right side of the shape.
The code you wrote says:
If "ImageRight" >= "ShapeLeft" then (a number equal to Image2.Right) = "Shape1.Left"

Since you're trying to check for the image going outside the right side of the shape, you shouldn't be comparing to "ShapeLeft".

The code also isn't even syntactically correct. You can't assign a number to a number. You can only assign a number to a variable.
(Image2.Left + Image2.Width) will return a number, for example, we'll say 319.
(Image2.Left + Image2.Width) = Shape1.Left would say
319 = 20 (assuming Shape1.Left was 20).
You can't make 319 = something else, it is a literal number.

If the right side of Image2 is determined by (Image2.Left + Image2.Width)
i.e ImageRight = Image2.Left + Image2.Width

how would you determine the right side of Shape1?
i.e. ShapeRight = ?

Hint: replace the word Image2 above with Shape1

So, your if statement should be along the lines
If ImageRight >= ShapeRight Then ImageLeft = ShapeRight - Image2.Width
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 12-20-2010 at 08:59 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Game Boundaries
Game Boundaries
Game Boundaries Game Boundaries
Game Boundaries
Game Boundaries
Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries Game Boundaries
Game Boundaries
Game Boundaries
 
Game Boundaries
Game Boundaries
 
-->