Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

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

"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
Posted (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 by Liu Junfeng
Posted
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.
Gamer extraordinaire. Programmer wannabe.
Posted

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.

.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?
Posted

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.

Posted

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

Gamer extraordinaire. Programmer wannabe.
Posted

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.

Posted

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.

Gamer extraordinaire. Programmer wannabe.
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...