I have tried searching and reading for an answer, but the information I could dig up either didn't fit what I need or was in the form akin to "Just multiply the vectors with the inverse matrix of.." which to my brain (unfortunately) makes just as much sense as someone speaking Mandarin.

The plan is to use requestAnimationFrame and canvas for the drawing, and WebSockets for the communication. I already have a fair grasp of requestAnimationFrame and canvas, and some hacked together code for a php WebSockets server with support for most of the currently-in-use drafts. This is a project for fun and learning so please, no comments on how silly it is to write server software in php

The main hurdle arises when I try to implement movement. I have code for drawing a map both as staggered and diamond shaped. I even had click-to-walk type movement implemented, but I hit a wall when it came time to implement collision detection.

See, my player exists in the coordinate system of the canvas, along with mouse events etc. What I did was draw the character sprite in the middle of the canvas, and animate the offset of the map by the difference between the center of the canvas and a clicked point. Thing is, I would like to keep my "world" (e.g. map, player, objects/entities) in memory as a regular grid map, and just have everything drawn with isometric skewing. This would make implementing collision detection very simple.

As it is right now, adding 32px to the players x-coordinate doesn't move him along the maps x-axis but rather that of the canvas. If increasing the player's x moved him along the maps x-axis then as I said, implementing collision detection would be as simple as checking whether the next tile along that axis is blocking or not, and update my x-position based on that.

Short question is: given the player's x- and y-coordinates, how do I calculate the appropriate map offset so that increasing either coordinate will move the player along the appropriate "in-game" axis?

Thanks, and a link to my hacked together initial test: http://dev.plastbox.org/isoengine/ It's continually being modified though, so it might not work at all every now and then.

  • 1
    \$\begingroup\$ consider revising, and cut the chase faster. also I do not feel that this has to do with your title \$\endgroup\$ – gardian06 Apr 29 '12 at 17:31
  • \$\begingroup\$ what about implementing traces (draw a line from the point on the screen the mouse exists on to the first thing it hits in the word) take the position of the camera, and the position of the pointer, and then do a ray trace to the game world \$\endgroup\$ – gardian06 Apr 29 '12 at 17:43
  • \$\begingroup\$ gardian06: Sorry for the long post. Didn't want to be yet another n00b asking for something without giving enough info for it to be possible to answer. The title is relevant because I have two different coordinate systems I need to convert between. I have the draw-offset of the map (where the player is), and I need to find the player's in-game coordinates. \$\endgroup\$ – PlastBox Apr 29 '12 at 17:53
  • \$\begingroup\$ I think canvas might be your problem (have not worked with php canvas, but have done work with other systems canvas) in order to work with the canvas, and translate between the canvas, and the world you need to use traces, but if you are able to implement a camera that is based on the players position in the world then that should clean up so much of the work for you, and you can implement cleaner. look into implementing a camera into your framework instead of canvas (as you said learning, and part of learning is stepping outside of comfort zone) \$\endgroup\$ – gardian06 Apr 29 '12 at 18:03

Your Answer

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

Browse other questions tagged or ask your own question.