How to make my character walk on the ground ?

Oct 8, 2010 at 5:34 PM

I use the map of the example to give it a try.

but I dont know how to make my character walk on the ground.

can anyone give me an answer ?

Oct 9, 2010 at 11:47 PM

First, you need to decide which layer you're going to use for the player. Assuming you're using the one in the example, it would be the fourth layer, to which you should keep a reference, for example

Layer playerLayer = map.Layers[3];

If you keep your player position (say a point representing his feet) as a Location object in absolute pixel coordinates (in layer space), then you can use the Layer object's GetTileLocation method to get the tile coordinates under the player:

Location tileLocation = playerLayer.GetTileLocation(playerLocation);

Once you have the tile location, you can get the actual tile as follows:

Tile currentTile = playerLayer.Tiles[tileLocation];

Depending on the tile, you can then decide what to do, such as, treating it as solid, or empty, a wall and so on. There are many ways of doing this, from simply checking the tile id, to keeping a separate invisible layer of the same size with special tiles to mark floors, ceilings, walls, ramps, etc.. An alternative is to use custom properties to identify the tiles.

Hope that helps.

 

 

Oct 10, 2010 at 10:04 AM
Edited Oct 11, 2010 at 4:32 AM
colinvella wrote:

First, you need to decide which layer you're going to use for the player. Assuming you're using the one in the example, it would be the fourth layer, to which you should keep a reference, for example

Layer playerLayer = map.Layers[3];

If you keep your player position (say a point representing his feet) as a Location object in absolute pixel coordinates (in layer space), then you can use the Layer object's GetTileLocation method to get the tile coordinates under the player:

Location tileLocation = playerLayer.GetTileLocation(playerLocation);

Once you have the tile location, you can get the actual tile as follows:

 

Tile currentTile = playerLayer.Tiles[tileLocation];

 

Depending on the tile, you can then decide what to do, such as, treating it as solid, or empty, a wall and so on. There are many ways of doing this, from simply checking the tile id, to keeping a separate invisible layer of the same size with special tiles to mark floors, ceilings, walls, ramps, etc.. An alternative is to use custom properties to identify the tiles.

Hope that helps.

 

 

Thanks for the replying.

But for my poor English and I'm new on xna, I really dont know how to make it work

Can you give me just a very simple example that can run on VS ?

I really want to make a game with this great tool

Sorry for taking your time

 

Oct 10, 2010 at 8:32 PM

I may eventually post a simple demo of a platform game but for now there are higher priority tasks I need to take care of.

P.S. For your own privacy I advise you avoid posting your email address in a public forum like this as it may be harvested by spammers.

 

Oct 11, 2010 at 4:34 AM

okay, I will try it myself and wait for the demo.

Thanks for your replying and advising. :D

Aug 11, 2011 at 3:32 AM

Bumping this one because I'm having a related problem. I have a sprite that renders after the map, and the map's viewport is being set to the sprite's coordinates every update, but the map scrolls too slow, almost like a parallax. Some kind of character demo would be really helpful.

Aug 11, 2011 at 1:18 PM

Nevermind, I figured out the proper offset. Just add the map viewport's coordinates to the character's location rect in the draw function and it synchronizes.