volfied applet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • silverblimp
    New Member
    • Mar 2008
    • 3

    volfied applet

    im making the game volfied(or xonics whatever version you know of it) as a java applet.
    the short version is that i have an array of 500x500 that emulates the playing field where theres a '1' the pixel corresponding on the playing field should be a different color and where theres a zero its the defualt white.
    problem is that painting pixel by pixel with drawrect(x,y,1, 1) is absurdly heavy
    with that big of an array and it makes the applet run slow.
    any thoughts would be appreciated.
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by silverblimp
    im making the game volfied(or xonics whatever version you know of it) as a java applet.
    the short version is that i have an array of 500x500 that emulates the playing field where theres a '1' the pixel corresponding on the playing field should be a different color and where theres a zero its the defualt white.
    problem is that painting pixel by pixel with drawrect(x,y,1, 1) is absurdly heavy
    with that big of an array and it makes the applet run slow.
    any thoughts would be appreciated.
    I have no experience in game programming...

    But i am interested in optimization...

    Can you post the part of the code that you have suspected to be the cause of the low performance?

    Sukatoa

    Comment

    • BigDaddyLH
      Recognized Expert Top Contributor
      • Dec 2007
      • 1216

      #3
      Take the Java2D tutorial: http://java.sun.com/docs/books/tutorial/2d/index.html

      It will give you lots of ideas.

      Comment

      • silverblimp
        New Member
        • Mar 2008
        • 3

        #4
        Originally posted by sukatoa
        I have no experience in game programming...

        But i am interested in optimization...

        Can you post the part of the code that you have suspected to be the cause of the low performance?

        Sukatoa
        public void drawmat(Graphic s gr){
        gr.setColor( Color.green );

        for (i=26;i<matsize-1;i++)
        for (j=26;j<matsize-1;j++)
        {
        if (dmat[i][j]==1)
        gr.fillRect( j, i, 1, 1 );
        }
        }

        this is the code and im looking at the tutorial mentioned.
        the problem is mainly that im redrawing the game board again and again when i dont have to as im working with only one image and only certain parts of it need to be redrawn. a solution i thought of today was to keep an array of images instead of just one and draw them only when needed.
        ill post the entire game code if anyone wants to see.

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Your code would speed up beyond belief if you used a BufferedImage. It's all in the Java2D tutorial I link to, above,

          Comment

          • silverblimp
            New Member
            • Mar 2008
            • 3

            #6
            the tutorial helped a lot. thanks.
            im using Buffered image and it runs a lot faster. not perfect but a lot better.

            Comment

            Working...