Results 1 to 8 of 8
  1. #1
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Default rendering question

    Im working on a project where i have to display many small squares on a grid, like a falling sands game. Im wondering if I could make my game run faster by drawing squares in groups as one big square? and if this would cause a speedup, how would I do it?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: rendering question

    In problems like this it is generally a good idea to to get the logic of the program solid (compiles,runs and passes your comprehensive tests so you're sure it is valid) before optimising things. The last thing you want is to be dealing with tricky painting code if the underlying stuff you are painting is buggy in some way.

    The effectiveness of the improved painting code will (like the proverbial pudding) be seen only once you have written it and measured the effect.

    -----

    That's not to say that someone here can't look at how you are painting and suggest something. (In my limited experience speedup will be associated with some *simplification* of the code.) But for that to happen you will have to post the code that you are using to paint. Others may be familiar with this "falling sands game", but I'm not. Code should compile and run, but be free from dependencies on other aspects of the program - no-one wants to wade through hundreds of lines of code to examine 20 or so that deal with painting. That is, the data you are painting should be "mocked" in some way: supplied to the painting code in some simple way like an array, but resembling the actual data that would arise as your program runs (having realistic "clumping" properties for instance).

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: rendering question

    This one didn't bother to return to the first thread started, not even to thank Norm.
    affecting other classes

    I don't really expect any better behavior here.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Default Re: rendering question

    Sorry, This is the first time I've checked back. As for my draw code, here it is:
    for(int i=0;i<width;i++){
    for(int n=0;n<height;n++){
    if(map[i][n]!=lmap[i][n]){
    g.setColor(inf.getCol(map[i][n]));
    g.fillRect(i*size, n*size, size, size);
    }
    }
    }
    width and height are the total number of cells, size is the size of each cell. g is the graphics 2d. Map[][] is what im drawing, it stores an int in each cell, and each int represents a different type of cell. inf.getCol(...) returns the color for each type of cell. lmap[][] is the map from the last refresh, i use it so that I can draw only the cells that have changed.

    Is there any quick way for me to detect groups of cells of the same type that are in a rectangle?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: rendering question

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

    Default Re: rendering question

    what?

  7. #7
    Vinx is offline Member
    Join Date
    May 2012
    Location
    USA
    Posts
    38
    Rep Power
    0

    Default Re: rendering question

    Quote Originally Posted by lolmister View Post
    what?
    He wants you to put code tags around your snippet.


    Java Code:
    for(int i=0;i<width;i++){
    for(int n=0;n<height;n++){
    if(map[i][n]!=lmap[i][n]){
    g.setColor(inf.getCol(map[i][n]));
    g.fillRect(i*size, n*size, size, size);
    }
    }
    As for the original topic itself, I apologize that I am unable to assist. I am just beginning Java.

  8. #8
    lolmister is offline Member
    Join Date
    May 2012
    Posts
    11
    Rep Power
    0

Similar Threads

  1. Rendering HTML???
    By jspexception in forum Networking
    Replies: 29
    Last Post: 01-30-2012, 08:28 AM
  2. Android PDF Rendering
    By iankitshah in forum Android
    Replies: 0
    Last Post: 08-17-2011, 06:18 AM
  3. Problem in JSP rendering
    By srkumarj2ee@gmail.com in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 09-27-2009, 02:02 AM
  4. Help with JTable rendering
    By daniel2008 in forum AWT / Swing
    Replies: 8
    Last Post: 01-18-2009, 03:51 AM
  5. JLabel Rendering
    By random4534 in forum New To Java
    Replies: 3
    Last Post: 12-16-2008, 08:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •