Skip to main content
GameDev.net gamedev.net
🔒 Locked

any 2d game code samples?

Started by ten Jul 13, 2003 at 1:35 PM 3 replies 450+ views
Original Post
ten
ten
hi, this is my first post here, I want some 2d games code programming with direct3d, do anyone have that? thank you!
RapidStunna
RapidStunna
First get the DirectX SDK if you don''t already have that (DirectX8/9 preferred). There are many ways to draw 2D objects in 3D:

1. Use billboards (rotated 3D quads that always face the camera) in a 3D environment.

2. Use transformed vertices. These are vertices that are known to D3D as vertices that have already been pushed through the transformations. You can set your vertices to match screen space and D3D won''t move them. You can do this by adding an RHW component to your vertex structure and seting that to 1.0f.

3. Use ID3DXSprite (VERY easy and fairly fast enough to use in a game!). I recommend that for people starting off because its fast for its ease of use.

4. UGH locking the frame buffer. DON''T do this. it''s slow (even with a lockable back buffer), and there''s too many variations in format. If you can avoid it, do that! Anyone that tells you differently should reconsider it themselves.

---

As for code, I won''t make it THAT easy for ya ;-) but i''ll point you to a few websites (from the articles and resources section, use that for future reference):

2D Rendering in DirectX 8

Gamasutra: 2D Programming in a 3D World

Possibly even: Dissecting Sprites in Direct3D

---
Brent Gunning | My Site
johnnyBravo
johnnyBravo
2D in direct3d is very easy.

A few things i believe you should learn from it is.
vertices eg squares, triangles
colouring
textures
alpha blending
moving vertices
sprites which also includes colour transparencies

ive got a bunch of these things in my program...ive learnt all that stuff really recently. Also includes basic matrix(that i don''t understand) and 2 3D matrices, but you can ignore that.

the code might be a little confusing , but just use it as a reference while you learn other tutorials

its in directx 9 by the way.
give me ya email and ill send it
(100kb)
ten
ten
thank you for all your helping!
these articles are very useful for me,
I should know how to write some simple 2d games now

to johnnyBravo, my email is cppii@hotmail.com, thanks for your code!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.