Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Havin' some graphicsprob

ErikoEriko Member Posts: 1
[b][red]This message was edited by Eriko at 2002-10-25 3:34:1[/red][/b][hr]
Hey! I am programming a little 2d tank game for an assignment.
I am kind of a newbie to graphics in java. I have already started and i have actually succeded to make a little image of a tank drive in various degrees on the screen the problem is that the graphics becomes really bad when i update both the location of the tank and the background and do you really have to update the background every update?
I have made the program in a swingframe using the drawImage method in graphics.
Do you have any tips?
Which classes and methods do you suggest me to use?



Comments

  • NazgulNazgul Member Posts: 63
    [b][red]This message was edited by Nazgul at 2002-10-25 4:38:59[/red][/b][hr]
    : [b][red]This message was edited by Eriko at 2002-10-25 3:34:1[/red][/b][hr]
    : Hey! I am programming a little 2d tank game for an assignment.
    : I am kind of a newbie to graphics in java. I have already started and i have actually succeded to make a little image of a tank drive in various degrees on the screen the problem is that the graphics becomes really bad when i update both the location of the tank and the background and do you really have to update the background every update?
    : I have made the program in a swingframe using the drawImage method in graphics.
    : Do you have any tips?
    : Which classes and methods do you suggest me to use?
    :
    :
    :
    :

    you have to use the double-buffering drawing method :
    first create an 'virtual image', called for ex. im ;-)
    in ur update(Graphics g) method :
    (but the easier way to do what u want is to extends canvas and redefine the paint method) :
    [code]
    Graphics g2;

    if(im==null){
    im = this.createImage(getWitdh(),getHeight());
    //Then get pointer to graphics of this Image :
    g2 = im.getGraphics();
    }
    [/code]

    Apply all your drawing methods to g2 graphics
    [code]
    if(g2!=null){
    //drawMyDangerousAndEnormousTankOnG2Please(g2);
    }
    [/code]
    Just before getting out of ur update(Graphics g) methods, paint the virtual image on graphics :

    [code]g.drawImage(im,0,0,width,height,this);[/code]

    Take care of not instanciate im if ur Frame is not visible and sized, creating an image with height and width at 0 make Exceptions.

    All paints methods are in a virtual image, and there is only one access to visible graphics, graphics that ur tank is going to destroy, anyway :-D





  • chamsterchamster Member Posts: 662
    You can try [blue]repaint (int, int, int, int)[/blue] instead of [red]repaint ()[/red]. That way, only a portion of the screen is being repainted.


    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    [email protected]
    http://konrads.webbsida.com

  • Andre YoungAndre Young USAMember Posts: 0

    ____ \ http://forcoder.org \ free ebooks and video tutorials about | Perl Swift Scratch C Delphi Go JavaScript R PL/SQL Visual Basic Objective-C PHP Python Java Visual Basic .NET C++ Ruby MATLAB C# Assembly Lua Rust Prolog Erlang VBScript COBOL Awk ABAP Hack Transact-SQL Kotlin Dart Alice Clojure LabVIEW Ada Bash F# Julia Logo Fortran Lisp ML FoxPro D Crystal Scheme Apex Scala SAS | _

Sign In or Register to comment.