Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+15 votes
asked in CSC211_Winter2018 by (8 points)

2 Answers

+9 votes

You can use BufferedImage objects in order to load images to be used later, like this:

BufferedImage birdImage = panel.loadImage("bird1.jpg");
BufferedImage birdImage2 = panel.loadImage("bird2.jpg");

They you can use g.drawImage(imageName, x, y, width, height, null); in order to draw the image.

In order to add sounds you can add panel.playSoundFile("fileName.wav"); to your methods in order to add sound effects when certain things happen, and you can use it when the game starts in order to play music.

answered by (8 points)
+7 votes

to add images and sounds to your program you can refer to the following examples, you can access it from moodle too.

                **Adding Images**

//import
import java.awt.image.BufferedImage;

  • // you can create BufferedImage objects to draw later

BufferedImage birdImage = panel.loadImage("bird1.jpg");
BufferedImage birdImage2 = panel.loadImage("bird2.jpg");
Graphics g = panel.getGraphics();

  • // image, x, y, width, height, null

g.drawImage(birdImage,200,450,600,150,null);
g.drawImage(birdImage2,0,300,100,50,null);

              **Adding Sound**
  • You should use .AU and WAV format sound files.
  • (But some WAV files didn't work for me... not sure why)
  • You can convert MP3 files into WAV or AU
  • using the free Audacity sound editing software.
             **panel.playSoundFile("meow.wav");**
    
answered by (8 points)
...