Help with the collisions

Jan 3, 2013 at 5:36 AM
Edited Jan 3, 2013 at 5:51 AM

Hey everybody!

I started making a platformer game with this nice engine. Everything works perfectly except the collisions. I'm using a layer for the collisions and have a tile texture for collision tiles. See pic below:

The collision tile has the Index 118

Here is my collision function:

 

    Private Function calculateCollision(ByVal newPos As Point)

        Dim tile As Tile
        Dim tileLocation As Location

        tileLocation = New Location(newPos.X / 32, newPos.Y / 32)

        tile = collision.Tiles(tileLocation)

        If tile IsNot Nothing AndAlso tile.TileIndex = 118 Then
            Return True
        End If

        Return False
    End Function

 

As you can see I'm writing my code in Vb.net which is not much different as C# and works just fine. Here is the same code translated via DeveloperFusion - Click :

 

private object calculateCollision(Point newPos)
{

	Tile tile;
	Location tileLocation;

	tileLocation = new Location(newPos.X / 32, newPos.Y / 32);

	tile = collision.Tiles(tileLocation);

	if (tile != null && tile.TileIndex == 118) {
		return true;
	}

	return false;
}

 

The real problem is, that the collision is not working properly. On same points its working on other not.

Is there a collision example everywhere or can someone give me one? C# is okay too. 

Thanks for helping and sorry for my bad english ;)

Jan 17, 2013 at 5:22 PM

Can nobody help? Just a simple collisions example would be help verry much.

Jan 17, 2013 at 8:31 PM

There are a couple of threads on collision if you search the discussion forum. One question that comes to mind is: which point does newPoint represent? This would typically be a point right under the player sprite's feet (not, say, the top-left corner for drawing the sprite).