In a browser game made in HTML5/Javascript, I would like to handle the move of units in real-time. But units would have to follow some predefined roads...
Canvas seems better than svg to handle complex games (by complex I mean like some Rome total war global map or conflict of nations map), but in svg lines are more clearly defined (with ). In canvas, I suppose I have to calculate the coordinates of the unit against the coordinates of the road in canvas to made the unit like "following" the road ? There is no some feature like "follow this path" ? I'm not even sure how to handle the coordinates of the road (it can be curved, not simple straight line).
Example of a move limited by road in a game (that uses canvas)
-
1\$\begingroup\$ This post could use more focus. What ONE question do you need help with first? (Note that "should I use SVG or Canvas" is not a question we'll answer — tech stack evaluation and selection is up to you. We'll help you solve problems with whichever one you pick). \$\endgroup\$DMGregory– DMGregory ♦2023年07月01日 12:08:43 +00:00Commented Jul 1, 2023 at 12:08
-
\$\begingroup\$ SVG and canvas are solutions to rendering the roads, so they seem to be unrelated to the question of implementing unit movement - whatever system you come up for modeling unit movement, can be rendered using either canvas or SVG (or even HTML elements). \$\endgroup\$Mattia– Mattia2023年07月01日 12:24:02 +00:00Commented Jul 1, 2023 at 12:24
-
\$\begingroup\$ In practice these kind of games (in the browser) are always made in canvas / WebGL. But you can have paths in canvas too. Just look at the moveTo, arc and lineTo commands for a start. \$\endgroup\$Kokodoko– Kokodoko2023年07月03日 09:35:56 +00:00Commented Jul 3, 2023 at 9:35