Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a dashed line in MonoGame / XNA

Tags:

c#

xna

monogame

What is the easiest way to draw a dashed line in MonoGame / XNA 4?

Should I use 3d primitives or can I achieve it with a simple sprite?

like image 322
adrin Avatar asked Mar 11 '13 22:03

adrin


2 Answers

The user C3 on bitbucket has published a nice utility class to create 2D primitives. These add extension methods to the SpriteBatch class. The repository is here : https://bitbucket.org/C3/2d-xna-primitives/wiki/Home


Welcome

Welcome to the new home of the 2D XNA Primitives project, now using a Mercurial repository on Bitbucket! Now compatible with Windows Phones.

Function Reference

All of the public methods provided by this library are extension methods, which means that you can access them directly through your very own SpriteBatch instance as if these methods were built-in to the SpriteBatch class. If you call the methods in this way, you can ignore the first parameter of all of the following calls.

Public Methods

DrawArc

DrawCircle

DrawLine

DrawRectangle

FillRectangle

PutPixel

like image 59
borrillis Avatar answered Nov 17 '22 03:11

borrillis


If it's a straight line (with simple 90 degree turns) then a sprite is probably the easiest.

(If you've got access to custom shaders via the HiDef profile then achieving dashed lines in shaders isn't too difficult if one keeps one's needs simple)

If it's twisting and turning in an irregular fashion then I would suggest using 3d primitives.

like image 20
lzcd Avatar answered Nov 17 '22 01:11

lzcd