|
-
Dec 14th, 2001, 07:40 PM
#1
Thread Starter
Member
Intersect Rect
I'm having trouble with collisions..
i am drawing a map using an array of tiles (which are picture box's) and i have been told to make a tile collidable i need to use intersect RECT
can anyone tell me how to do this?
Cheers
-
Dec 14th, 2001, 11:09 PM
#2
Good Ol' Platypus
The reason why most games don't use pictureboxes for each tile is that it requires 4 draws of the character, one for each part of a picturebox he's in (on rare occasions it could be 1 or 2). That's why there's one large picturebox and all of the tiles are blitted on. Then the character is.
Anyways, IntersectRect works seeing if two RECTs are intersecting. For example:
VB Code:
Dim X As RECT: Dim Y As RECT
X.Left = Chara.NextX
X.Top = Chara.NextY
X.Right = Chara.NextX + Chara.Width
X.Bottom = Chara.NextY + Chara.Height
Y.Left = Tree.X
Y.Top = Tree.Y
Y.Right = Tree.X + Tree.Width
Y.Bottom = Tree.Y + Tree.Height
If Not IntersectRect(X, Y) Then
Chara.NextY = Chara.Y
Chara.NextX = Chara.X
End If
An ideallistc sample at best, this says you have a tree and a character, and the character & tree have X, Y, Height, and Width properties. Normal stuff. The chara also has a nextx & y, which is where you are moving them. You can simply use something like this before drawing, to make sure that the character doesn't move into said "tree".
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Dec 15th, 2001, 06:09 AM
#3
Thread Starter
Member
but doesn't that mean i have to declare it for every tile on my map? is there a way i could use interesect RECT with everysingle tile (1) on my map?
-
Dec 16th, 2001, 10:43 AM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|