PDA

View Full Version : 2D Shapes in XNA



xcal
11-11-2009, 10:54 PM
I'm struggling to find any info on this...

Java helped me to draw 2D shapes easily by simply adding the points that outlined the shapes... I was hoping that XNA would provide more advanced tools for doing this so I could draw rounded shapes, but for the life of me I can't find article on the net that show me how to actually draw a shape?

Any help would be much appreciated, and especially any help regarding drawing CURVED shapes, such as the shape of a cell or a water droplet.

Thanks in advance!

Chippit
11-11-2009, 11:37 PM
I'm afraid there's no real quick and easy solution for this. You can write a custom shader to do curve interpolation over triangles (which isn't that tricksy), but the easiest way is to just subdivide your curves into line sections and just draw it as a line strip. It's not quite a curve, but it often comes close enough that you don't notice.

xcal
11-11-2009, 11:48 PM
MMM... I'm way too Noob to understand what you just said...

*Goes to read in the corner*

But seriously, my only experienc so far is about on the GDI+ level of graphics, and what the JAVA 2D API offers. I think I'm gonna have to dive into XNA 3D to handle this... Tomorrow though...

dislekcia
12-11-2009, 02:00 PM
MMM... I'm way too Noob to understand what you just said...

*Goes to read in the corner*

But seriously, my only experienc so far is about on the GDI+ level of graphics, and what the JAVA 2D API offers. I think I'm gonna have to dive into XNA 3D to handle this... Tomorrow though...

Yeah, those old GDI routines are actually completely unlike anything in "standard" graphics for games. They're often horribly misleading :(

If you're trying to draw any sort of curve or shape in a 3D-centric API (meaning it uses polygons and vertices to define what stuff should look like) then you've got two options: Either "cut up" your smooth shape into a lot of little straight line segments so that those look smooth when you put them together; Or use a texture (or pixel shader, but don't worry about those just yet) to make a single big polygon look like it's actually got a curve on it.

Fengol
12-11-2009, 03:01 PM
I would recommend using textures and learning about the spritebatch in XNA for 2D graphics.

Can I recommend Riemers XNA Tutorial 2D Series (http://www.riemers.net/eng/Tutorials/XNA/Csharp/series2d.php) where he covers:

# Installing XNA and opening your first XNA project
# Rendering 2D images to the screen
# Scaling, rotating and positioning 2D images
# Keyboard input
# Playing sound effects in XNA
# Per-pixel texture manipulations
# Random terrain slope generation
# Alpha blending
# Collision detection (the most complex case is covered: per-pixel transformed)
# And even a complete 2D particle engine for the explosions!