My game a sidescrolling platformer. I've created my own Tile app which in the end export an xml file detailing what each 32x32 space (in the entire image) contains (environment, platform, etc.). I get how to use it for static things/collision detection and quad trees and so forth but still have no clue how to use this map xml file for keeping my character on a path in my background image which in my case is a hill with lots of odd curves.

Also, yes, there are tutorials on tile movement, but they are mostly movement from a top-down view which is slightly more trivial to implement. 80% of the image in my game is just a pure background and the very bottom are bricks covered with grass with some weirder angles. The thing is, I can have mixed tiles of empty space and grass which contains a part of a curve so I don't know how I would want the player leg to interact with this. Can anyone give me an idea or an example?


As long as I understand you have two problems:
1- you don't exactly know where the curves begin end or their functions.
2- where your characters feet touch.

If your characters collision behavior means just its Y position and keep its feet above the curve then:

  1. Get your characters begin X and end X. Let's say x1,x2 to these.
  2. Assuming you don't know what background there's someway you should get the image pixel data from the background falling between x1 and x2.
  3. Then apply an edge detection algorithm(you may find immense number of libraries and code snippets around) to your partial background.
  4. Edge detection will provide the edges of your background in white or black so looping down from the max y value of your platform you can find where the first edge pixel is. You may threshold the resulting edge detected image for better results.
  5. Place your charater where the first edge is found.

Note that if your curves on the background are very ambiguous edge detection may fail but I think this solution will be a swift and adequate one.

  • \$\begingroup\$ So, I'd can set my player on my choice of a walkable tile to the very left of a scene. Then, I can simulate my player moving to the right. To the lower-right of this move might be a walkable tile and to the right might be just thin air which are mapped to my xml. Could I just then get the first max x-position in the lower right walkable tile and set my player's foot to there. In terms of the curve thing, thanks, I'll take a look. \$\endgroup\$ – Ilya Oct 5 '10 at 11:12
  • \$\begingroup\$ Another way I was thinking is to just set a visible (or invisible) stroke with specific RGB combination as a line on the top of my path, calculate the points before rendering the scene and then just use these points as my path. What do you think about this and my above comment? \$\endgroup\$ – Ilya Oct 5 '10 at 11:20
  • \$\begingroup\$ I would just edit my answer for a specific color like you mentioned but you're faster :). But I like things automated more. If you have performance issues stroking the curves with a specific color will save you edge detection calculation times for a cost of stroking every walkable curve and a thin curve line. But this will prevent you from generating random things and random things add much more fun to the game. \$\endgroup\$ – Gorky Oct 6 '10 at 7:21
  • \$\begingroup\$ For the xposition you may again use edge detection. If your thin air colors are light enough by thresholding along with edge detection you may calculate the foot position will be zero meaning there are no edges. So you may block your character to move forward anymore. You may let it jump or fly or other. I would preffer falling myself :) \$\endgroup\$ – Gorky Oct 6 '10 at 7:21

Someone else with more knowledge of the subject should write a more thorough answer, but in an attempt to give you an answer (since nobody else has)...

You should start by implementing pixelwise collision detection, or triangles (mesh collision) if they approximate your terrain well enough. Then, in order to accurately place your character's feet on the ground, perhaps rig your sprite with virtual bones. They could be controlled by a physics engine for best-looking results. Or, if you go the triangles way, you could also have a triangle collision mesh for your sprite, and borrow some of the techniques usually used in 3D games in order to calculate the best angle/distortion of the collision mesh onto the terrain.

  • \$\begingroup\$ Heh I used feet as a placeholder, the character I have just has a wheel so it's not as much of a pain. But I still can't figure out, even though you have designated walking tiles, how people can use this designation in order to create their walking path for the player. \$\endgroup\$ – Ilya Oct 4 '10 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.