Jump to content
  • Advertisement
Sign in to follow this  
Robin91

Vb.net direct X sprites

This topic is 3490 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im trying to code an little 2D platform game in vb.net. Nothing big just simple. I made it all work, but the FPS was really low because i was using the gdi engine to draw. Now im moving to direct X i encounter an big problem where i cant find an solution for, because i dont have experience with direct X. How to call multiple sprites at an efficent way? And what is the best way to move it all? i have been trying ofcource and got this:
            'Sprite to be rendered
            Dim Alex As Direct3D.Sprite
            'Texture for the sprite
            Dim AlexTexture As Texture
            'Background Transparent Color
            Dim ColorKeyVal As Color

            Dim i As Integer = 0
            Do While Not Form1.collision(i, 1) = Nothing
                Alex = New Direct3D.Sprite(D3Ddev)
                ColorKeyVal = Color.FromArgb(255, 0, 255, 0) 'LimeGreen 
                AlexTexture = TextureLoader.FromFile(D3Ddev, Form1.Dir & "Map/" & Form1.collision(i, 0), CInt(Form1.collision(i, 3)), CInt(Form1.collision(i, 4)), D3DX.Default, Usage.None, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, ColorKeyVal.ToArgb)
                Alex.Begin(SpriteFlags.AlphaBlend)
                Alex.Draw2D(AlexTexture, New Point(0, 0), 0, New Point(CInt(Form1.collision(i, 1)), Form1.Height - (20 + CInt(Form1.collision(i, 2)) + CInt(Form1.collision(i, 4)))), Color.White)
                Alex.End()
                i += 1
            Loop
Form1.collision is an multidemensional array storing the collision points where the character have to stop + the image. The problem is this is not so efficient and alot worser then the gdi engine.

Share this post


Link to post
Share on other sites
Advertisement
It's almost never a good idea to load stuff everytime you use it!

Other than that, in Direct3D Sprite is actually not that good a name for what that class realy does. It's actually used to draw large batches of sprites at once. So you don't need multiple instances of Direc3D.Sprite but just one.

So, to do it right, you should create a method/function that gets called right after your Direct3D device was created where you:
1. Create a single instance of Direct3D.Sprite
2. Load all the textures needed

Then, when you want to draw your scene you:
1. call sprite.Begin
2. call sprite.Draw2D for every sprite you want to draw
3. call sprite.End

Share this post


Link to post
Share on other sites
Thanks for your reply at my thread, but since im an beginner with directX i dont know how to do it.

I have moved some lines to the initalize sub, but this is really the best i can come up with:



Dim i As Integer = 0
Do While Not Form1.collision(i, 1) = Nothing
AlexTexture = TextureLoader.FromFile(D3Ddev, Form1.dir & "Map/" & Form1.collision(i, 0), CInt(Form1.collision(i, 3)), CInt(Form1.collision(i, 4)), D3DX.Default, Usage.None, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, ColorKeyVal.ToArgb)
Alex.Begin(SpriteFlags.AlphaBlend)
Alex.Draw2D(AlexTexture, New Point(0, 0), 0, New Point(CInt(Form1.collision(i, 1)), Form1.Height - (20 + CInt(Form1.collision(i, 2)) + CInt(Form1.collision(i, 4)))), Color.White)
Alex.End()
i += 1
Loop



It doubles the FPS to +- 50 but thats really to slow since it only draws like 10 sprites.
It needs be be able to draw an map with 200 sprites or something close to that.


Could anyone help me with some code?
You dont have to write it out for me, i just want to know how to store the images once and draw then fast and efficient, with an example if possible.

Share this post


Link to post
Share on other sites
Are you using Managed DirectX? MDX is a dead project, MS stopped supporting it years ago. SlimDX on the other hand is currently well-maintained, and is getting a lot of use.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!