June 2005
Beginner to intermediate
336 pages
6h 29m
English
The drawFishImage method draws the fish when needed in the memory-based image before that image is flashed onto the screen. This method is passed the Graphics object it should use to draw the fish.
Drawing the image isn't hard; all you need to do is to use the Graphics object's drawImage method to draw the fish at its position as given by its location object. The only subtlety here is that you should draw the image of the fish going to the left if its x velocity is negative, and going to the right if its x velocity is positive. Here's what it looks like in the drawFishImage method:
public void drawFishImage(Graphics g) { if(velocity.x < 0) { g.drawImage(image1, location.x, location.y, tank); } else { g.drawImage(image2, location.x, ...Read now
Unlock full access