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
Printable View
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
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: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".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
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?
It's easy, instead of a Tree, use the tile where the player is about to move to :) (for example Map(PlayerX, PlayerY-1) if he's moving up ;)