Liu Junfeng Posted August 21, 2003 Posted August 21, 2003 I want to use a big map in my little game, but the srolling is rather slow. How to create a surface whose width and height are larger than the display device? Quote
*Experts* Nerseus Posted August 21, 2003 *Experts* Posted August 21, 2003 In general, you don't want to do that. A surface is essentially a texture which has limits on most cards (256x256 is not uncommon, though you might find 2048x2048 on *some* cards). If you're talking about 2D or 3D with a background, you'll need to piece together multiple surfaces, usually. DirectDraw has some built-in methods, if I remember correctly, for handling large surfaces more easily thand Direct3D. But if you're talking about a game map that's bigger than the screen, you'll need some kind of tile-based layout (the most common). -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Liu Junfeng Posted August 21, 2003 Author Posted August 21, 2003 (edited) Thanks for your explanation, currently my code like this: //------------------------------------------------------------------------ public void DrawTile(int x,int y,Tile pic) { int w=pic.Width; int h=pic.Height; Bitmap bm=pic.ImageData; bool cut=false; if(pic.Width>ScreenWidth-x) { w=ScreenWidth-x; cut=true; } if(pic.Height>ScreenHeight-y) { h=ScreenHeight-y; cut=true; } if(cut) { Rectangle srcRect=new Rectangle(0,0,w,h); bm=pic.ImageData.Clone(srcRect,pic.ImageData.PixelFormat);//GDI+ Function } description.Clear(); description.SurfaceCaps.OffScreenPlain=true; Surface surface=new Surface(bm,description,display); back.DrawFast(x,y,surface,DrawFastFlags.Wait); surface.Dispose(); } //--------------------------------------------------------------------------- The mixed use of DirectDraw and GDI+ make the draw speed very slow. How to solve this problem? Is there a similar problem in Direct3D? Edited August 21, 2003 by Liu Junfeng Quote
wyrd Posted August 21, 2003 Posted August 21, 2003 Well, one thing you want to avoid is cloning an image and creating a new surface everytime you draw a tile. :) Create an array of surface tiles (lookup table) that's created when the class is instantiated, then you can just snag the already built surfaces without having to go through the pain of creating them each time you draw. Quote Gamer extraordinaire. Programmer wannabe.
Liu Junfeng Posted August 21, 2003 Author Posted August 21, 2003 But the x and y position are not foreseeable; if I use 8 pixels as the step of x and y, then how many surfaces should I create ? Quote
AndreRyan Posted August 21, 2003 Posted August 21, 2003 You should create a Surface, not a Bitmap. Put the surface in an array an use: public void DrawTile(int x, int y, int SurfNum) { back.DrawFast(x,y,SurfaceArr(SurfNum),DrawFastFlags.Wait); } Just load the pictures in to surfaces at the start of the program and then Blt the surfaces instead of creating it each time. Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Liu Junfeng Posted August 21, 2003 Author Posted August 21, 2003 I tried so, the image file is 1024*768;divided into 16*16 cells and create surfaces of 640*480, then more than 100M memory is used; if use 8*8 cell, outofmemory exception occured. SO, for a scrolling game, you can't create surfaces for each frame at the same time. If I create surfaces of size 16*16, the memory is ok, but the drawing speed is even slower. Quote
wyrd Posted August 21, 2003 Posted August 21, 2003 Ah, yeah memory usage. Forgot about that. :) Instead of holding surfaces in the array, just hold Rectangle structures that describe the image itself, so you can draw it directly off your tile bitmap and not have to create any extra surfaces. You may also want to take a look at my Map class in my Sharp Invader game. What I did was create a two-dimensional array, which basically was my map. The two-dim array was made up of objects, each describing a tile on the map. They didn't hold surfaces or bitmaps, just info that you could draw based off of. That way you have no extra surface, but just 1 single image of your tiles. There are also several tutorials on GameDev.net about how to make tile and isometric map engines. You may find them useful. http://www.gamedev.net/reference/list.asp?categoryid=44 Quote Gamer extraordinaire. Programmer wannabe.
Liu Junfeng Posted August 22, 2003 Author Posted August 22, 2003 But there isn't a function such as public void Draw( Rectangle destRectangle, Bitmap source, Rectangle srcRectangle, DrawFlags flags ); There only exists: public void Draw( Rectangle destRectangle, Surface sourceSurface, Rectangle srcRectangle, DrawFlags flags ); After reading "Using Direct3D For 2D Tile Rendering ", I think I should learn Direct3D first. Quote
wyrd Posted August 22, 2003 Posted August 22, 2003 Well, even so the logic of a tile based map engine is the same (so your map isn't drawn so slowly.. which was one of the problems you were having I believe). You'll just need to convert the Bitmap into a Surface. For that I can't help you. :) I don't know DirectX. Hopefully someone else will pop in and help you out with that. Also.. have you considered learning DirectDraw instead of Direct3D? If you're doing a simple game then Direct3D would be overkill and is much harder to learn IMO. Quote Gamer extraordinaire. Programmer wannabe.
Liu Junfeng Posted September 28, 2003 Author Posted September 28, 2003 I recreated wyrd's SharpInvader game with Managed Directdraw; you can download it from: http://www.funnyok.net/rufi/ware/Invader.rar Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.