Hi I have a tile based game and I would like to know how to animate the grass image this is what I have so far:
public class dirt extends block{
float frame = 0;
public dirt(int x,int y){
this.x = x;
this.y = y;
r = new Rectangle(x - (int)tilemap.camx,y - (int)tilemap.camy,20,20);
solid = false;
}
public void tick(){
createCollisionRect();
int tester = (int)(frame +.1);
if(tester < 3){
frame+=.1;
}else{
frame = 0;
}
}
public void render(Graphics g){
ImageIcon i62 = new ImageIcon("res/grasssheet.png");
img = i62.getImage();
g.drawImage(img, x - (int)tilemap.camx,y-(int)tilemap.camy,x+20,y+60/***/,0,20*(int)frame,60,20*(int)frame + 20,null);
//g.drawImage(img, x- (int)tilemap.camx,y-(int)tilemap.camy, null);
}
}
This kinda works but I don't why all the images glitch out.
I think I need an image observer but I don't understand that so if that's the problem explain what I have to please.