Sign in to follow this  
EvilNando

[.net] Slow picturebox performance

Recommended Posts

Hi guys, im making a tilemap editor for my game the idea is to decompose a big image where all the tiles are contained and slip the tiles into a separate picturebox, that way I can create some sort of tile pallete where I can click the desired picturebox and apply it to my map the problem is that the map I also constructed from pictureboxes so when I try to create a map of 100x100 tiles the system crashes when trying to allocate so many control handlers how can I achieve this? I dont want to use gdi+ because I want to have click events for each grid in the map so i know to wich cell i am applying the tile I want heres a small picture of my palleteloader form so you can have an idea of what I am talking about thanks (Once upon I time i used to work with something called flexgrid but now its nowhere to be found , why?) the relevant code
[SOURCE]
    private void resize_Click(object sender, EventArgs e)
    {
      //foreach (PictureBox p in panel_tile_map.Controls)
      //{
      //  p.Dispose();
      //}

      Tile[,] aux_tile = new Tile[(int)updwn_width.Value, (int)updwn_height.Value];

      for (int id_y = 0; id_y < updwn_height.Value; id_y++)
      {
        for (int id_x = 0; id_x < updwn_width.Value; id_x++)
        {
          aux_tile[id_x, id_y] = new Tile();
          aux_tile[id_x, id_y].id = -1;
          aux_tile[id_x, id_y].rectangle.X = id_x * this.tile_set.tile_size.Width;
          aux_tile[id_x, id_y].rectangle.Y = id_y * this.tile_set.tile_size.Height;
          aux_tile[id_x, id_y].rectangle.Size = this.tile_set.tile_size;
          aux_tile[id_x, id_y].picturebox.Location = new Point(aux_tile[id_x, id_y].rectangle.X, aux_tile[id_x, id_y].rectangle.Y);
          aux_tile[id_x, id_y].picturebox.Size = aux_tile[id_x, id_y].rectangle.Size;
          aux_tile[id_x, id_y].picturebox.BackColor = Color.DarkGray;
          aux_tile[id_x, id_y].picturebox.BorderStyle = BorderStyle.FixedSingle;

          panel_tile_map.Controls.Add(aux_tile.picturebox);
        }
      }




Share this post


Link to post
Share on other sites
Hello,

I would reconsider using GDI+ though and just use the big image. It's not so difficult to figure out which tile you clicked.
And I'm not sure here, but chances are that you'll need the same logic in your game anyway.

Another possibility would be to only construct the visible pictureboxes.

kind regards
Uncle

Share this post


Link to post
Share on other sites
Remus is correct. Overlaying a grid in GDI+ is trivial -- as is detecting where you clicked. Check out Bob Powell's website for some hints on how to get started (it is really not that hard).

Good luck :)

~Shiny

Share this post


Link to post
Share on other sites
One more for going GDI+. Just find where the user clicked; calculate the tile; and draw and save the tile.

Also, use a Panel, not a picturebox.

Share this post


Link to post
Share on other sites
I would tackle that problem from another angle.

You're loading into memory a big amount of resources that the user won't immediately need, so you could just load the part of the map that the user is looking at, and not the entire thing, updating it when the user scrolls into a section of the map that isn't loaded yet, and freeing the resources from the parts of the map that got pushed out of vision.

You would get a much smaller memory footprint and also better performance.
It would probably require a minimap thingy, to complement the interface as well.

In retrospect, handling this dynamic resource allocation and creating a minimap might be a bit more work then you want to put into it, still, I think the end result would be worthwhile.

Share this post


Link to post
Share on other sites
Oh reading this last post has reminded me that I need to handle layers as well ( 3 layers minimum) will I still be able to use pictureboxes or gdi is the only way to go?

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilNando
Oh reading this last post has reminded me that I need to handle layers as well ( 3 layers minimum) will I still be able to use pictureboxes or gdi is the only way to go?


GDI is the way to go for pretty much everything that requires custom drawing.

Using controls stacks to simulate grids or lists is very limiting and nonperforming, except for the most simple of scenarios.

One way or another this is an old issue, people have tried to use lots of controls to composite a bigger control since the introduction of WinAPI and the result has alway been the same in the end they have reached the handle count limit.









Share this post


Link to post
Share on other sites
Quote:
Original post by Cryogenic
Quote:
Original post by EvilNando
Oh reading this last post has reminded me that I need to handle layers as well ( 3 layers minimum) will I still be able to use pictureboxes or gdi is the only way to go?


GDI is the way to go for pretty much everything that requires custom drawing.

Using controls stacks to simulate grids or lists is very limiting and nonperforming, except for the most simple of scenarios.

One way or another this is an old issue, people have tried to use lots of controls to composite a bigger control since the introduction of WinAPI and the result has alway been the same in the end they have reached the handle count limit.


/cry


thanks for the facts, ill just start with gdi in mind right now, back to the notebook

thanks again


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this