Archived

This topic is now archived and is closed to further replies.

Wutz2003

Need help with 2D-Tile-Engine

Recommended Posts

Hey guys! Over the last three weeks, I''ve been working on a 2D puzzle game, using VisualBasic and DirectX 8. It''s a clone of an older game. This is what it looks like so far: http://www.steffenwenz.de/fotos/reoxid-screenshot1.png http://www.steffenwenz.de/fotos/reoxid-screenshot2.png As you can see, the game consists of (40x40 pixels) tiles. I''m using the D3DXSprite class to draw the graphics, and it works fine. But the way I''m doing it right now is that I draw every tile in every frame. I wouldn''t know how to do it differently. But wouldn''t it speed up the performance to draw the level background once when the level is loaded, save the level background somewhere, and then draw that as a whole instead of drawing tile by tile? Can anyone tell me how that is done basically? I''ve tried setting the RenderTarget to a texture, but I guess I have too little knowledge to get that working. And, by the way, I can''t exactly read C++, so if you know a solution, please put it in words or at least pseudo-code

Share this post


Link to post
Share on other sites
Ways I would have done this (in C++, so this might not be possible) :

-Create a vertex buffer to store screen-space polygons ("XYZRHW"), then render that vertex buffer once per frame (it will contain everything that isn't dynamic).

-Create a big texture or two (say, two 512*512 textures, but can be overkill), then using copyrects, draw over the textures the background. Then, show the parts of these textures that contain background.

-In the good old DirectDraw days, I would render the background once for all, and then, I wouldn't clear the screen each frame, only refresh the tiles I need to redraw.

How? Create a boolean array (one value per tile). Get all dynamic effects (player, opening pyramids, lasers, etc) at the end of your frame, and using their position, determine which tiles they overlap, and mark these as "true" in the array - they'll need to be redrawn, since the objects will move. Then move the objects. Render your frame - only render marked tiles, and then the moving objects. Clear the array and start all over again for the next frame.

Side note: I LOVE oxid ;-) Contact me if you need ANY help with it, or have any demos to test :-D

EDIT - Repeated a sentence...

[edited by - ToohrVyk on December 26, 2002 12:15:20 PM]

Share this post


Link to post
Share on other sites
I''ve been gone for a couple of days, so here''s my late reply...

ToohrVyk: Thanks for your advice! I tried doing the first two things you proposed, but I couldn''t get them to work. By using the D3DSprite class, I didn''t have to mess with any vertex buffers at all, and I didn''t want to change that

But your idea with the boolean array and redrawing only what''s needed worked great, thanks for that The only problem I encountered is that I have to draw everything at least twice, otherwise it''ll just flicker on the screen. I guess it''s because it needs to be on the back buffer and the front buffer because they''re constantly swapped. But once I had figured that out, it was easy to solve. Now it works!

"Contact me if you need ANY help with it, or have any demos to test" - I think I''ll have a demo ready soon, so if you really want to, you could test it. So far, I''ve just included the easier objects and items. Lasers and doors and puzzles and all that horrible stuff aren''t done yet... Oh, I would also need help designing levels for reOxid. That''s the fun part of it all!

Peti: The reason why I''m using D3D and nothing else is that I found the documentation for D3D first, and then stopped looking for other things

Share this post


Link to post
Share on other sites