Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,099 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,645 people online right now. Registration is fast and FREE... Join Now!




Displaying hundreds of images effciently

 
Reply to this topicStart new topic

Displaying hundreds of images effciently

awesty
8 Nov, 2007 - 03:05 AM
Post #1

D.I.C Head
Group Icon

Joined: 27 Oct, 2007
Posts: 76


Dream Kudos: 25
My Contributions
I am making a tile based map editor for a game I am making. I just have a 2 dimensional picture box array to display each 25x25 tile. This works fine when the map is 10x10 tiles (which isn't much of a map) but much bigger and the program starts to run really slow.

Is there a more efficient way to display a lot of images?
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Displaying Hundreds Of Images Effciently
8 Nov, 2007 - 11:06 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
That really depends on how you are doing it now. Can you post your code?
User is offlineProfile CardPM
+Quote Post

awesty
RE: Displaying Hundreds Of Images Effciently
8 Nov, 2007 - 10:11 PM
Post #3

D.I.C Head
Group Icon

Joined: 27 Oct, 2007
Posts: 76


Dream Kudos: 25
My Contributions
At the moment the picture boxes don't actually display any images, but here is the code.

CODE
private void initMap()
        {
            for(int i = 0;i<tilesNum.GetLength(0);i++)
                for (int j = 0; j < tilesNum.GetLength(1); j++)
                {
                    tiles[i, j] = new PictureBox();
                    tiles[i, j].Name = "tile" + i + "_" + j;
                    tiles[i, j].Size = new Size(25, 25);
                    tiles[i, j].Location = new Point(j * 25, i * 25);                    
                    tiles[i, j].BackColor = Color.Aqua;
                    tiles[i, j].Visible = true;
                    sc.Panel1.Controls.Add(tiles[i, j]);
                }
        }        


This post has been edited by awesty: 8 Nov, 2007 - 10:14 PM
User is offlineProfile CardPM
+Quote Post

skaoth
RE: Displaying Hundreds Of Images Effciently
9 Nov, 2007 - 02:30 PM
Post #4

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 342



Thanked: 10 times
Dream Kudos: 100
My Contributions
Since I don't know whats going to be on a tile, or if they will at some point be
different from one another it a little difficult to help.

However, the code you provided indicates that all the tiles are the same.
One method you might think about is to have 2 arrays;

(I assume that each tile object knows how to draw itself)

1st is the 2-d array you already have.
2nd is 1-d array that contains unique types of tiles.

The 2-d array will just reference the tiles in the 1-d array.
An example may help clarify;

Lets assume I have 2 types of tile objects :
1 has a picture of a tank on.
2 has a picture of a soldier on it.

My 1-d array then will have only these 2 tile objects.
e.g
1dArray[0] == TankTile;
1dArray[1] == SoldierTile;

Then I can set the 2-d array grid to point to one of these tiles.
So instead of having its own object, it will have a reference to the tile object.
(Warning: I haven't tried this)

The should reduce the number of objects that needs to be created.
However, this method doesn't help if each tile needs to be independent
from every other tile (e.g: needs to be its own object)
Does this make any sense? and hope it helps.

This post has been edited by skaoth: 9 Nov, 2007 - 02:33 PM
User is online!Profile CardPM
+Quote Post

awesty
RE: Displaying Hundreds Of Images Effciently
9 Nov, 2007 - 03:19 PM
Post #5

D.I.C Head
Group Icon

Joined: 27 Oct, 2007
Posts: 76


Dream Kudos: 25
My Contributions
But I will still need to put a heap of picture boxes on the form to display the tiles anyway won't I?

EDIT: Nevermind I am just using XNA now.

This post has been edited by awesty: 10 Nov, 2007 - 02:23 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:45PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month