2d games - Java Image Drawing -


i'm in process of making simple 2-d game, having trouble drawing images. below few classes relevant problem

private vector<bullet> ammo = new vector<bullet>(100);  public class bullet{     image img;     int x, y, speed;     boolean show;     bullet(image img,int x, int y, int speed, boolean show){         this.x = x;         this.y = y;         this.speed = speed;         this.img = img;         this.show = show;     }     public void draw(imageobserver obs) {         if(show)             g2.drawimage(img, this.x, this.y, obs);     }     public void update(){         this.y -= 1;     } }  public class movement{     ....      movement(....){         .....     }      public void fly(){         ......          ammo.add(new bullet(bullet1, m.x, m.y, 7, true));    }    public class myplane {      keycontrol key;     movement flight;     image img;     int x, y, speed, move = 0;     int boom;     ... }   public void drawdemo() {        ...                 for(bullet bullets: ammo)             bullets.update();     ...         for(bullet bullets: ammo)             bullets.draw(this);     } } 

when call bullets.draw(this) nothing drawn on screen. know ammo vector contain correct information, such x coordinate, y coordinate... i'm using graphics 2-d way. , or suggestions appreciated thanks.

 public void paint(graphics g) {     if(bimg == null) {         dimension windowsize = getsize();         bimg = (bufferedimage) createimage(windowsize.width,                  windowsize.height);         g2 = bimg.creategraphics();     }     drawdemo();     g.drawimage(bimg, 0, 0, this); } 

i think should draw image this:

public void draw(graphics g2) {     if(show)         g2.drawimage(img, this.x, this.y, null); } 

then in plane class have add graphics argument of drawdemo() method:

public void drawdemo(graphics g2) {    ...             for(bullet bullets: ammo)         bullets.update(); ...     for(bullet bullets: ammo)         bullets.draw(g2); } 

}

and in paint(graphics g) method call this:

public void paint(graphics g) {    /*       ...    */    drawdemo(g2);    g.drawimage(bimg, 0, 0, this); } 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -