Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Applet won't work at all...  (Read 1369 times)
0 Members and 1 Guest are viewing this topic.
Offline CyanPrime
« Posted 2009-09-09 15:43:47 »

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.BufferedImage;
import java.awt.image.BufferStrategy;
import java.net.URL;


public class AppletGame extends Applet implements Runnable
 {
   Image bg;
   //Global Variables
   BufferedImage bi;
   Graphics2D g2d;

   Stars stars1, stars2;
   boolean playing = false;
   
   public static final int MAX_SOUNDS = 1;
   AudioClip[] sounds;
   //Initialize the Applet
    public void init() {
       
       //Set the size
       setSize(640,480);
       
       //Create double buffer
       bi = new BufferedImage(640,480, BufferedImage.TYPE_INT_RGB);
      g2d = bi.createGraphics();
       
      //Load Display class

      
      //Load Stars class
      stars1 = stars2 = new Stars();
      
      try
      {
         bg = getImage(getCodeBase(), "data/bg.png");
      }
      
      catch(Exception e)
      {
         System.out.print("Error loading Graphics");
      }
      
      //Load sound
      sounds = new AudioClip[MAX_SOUNDS];
      
      URL url;
       for(int i = 0; i < MAX_SOUNDS; i++)
       {
         url = this.getClass().getResource("data/test" + i + ".au");
           sounds = getAudioClip(url);
       }


       playSound(0);

      Thread t = new Thread(this);
        t.start();

      
    }

    public void destroy() {
    }

    public void start()
    {
       //Initialize sound

    }
   
    public void playSound(int num)
    {
          // This will play your sound file.
       if(!playing)
         sounds[num].play();
       
       playing = true;
    }
   
    //Basically our main method
    public void run() {
       
       
       
       //Our game loop
       while(true)
       {
          //Make the stars move
          stars1.starAI();
          stars2.starAI();
          
          //Call repaint
          repaint();
       }
    }
   
    //Stops graphics from flickering.
    public void update(Graphics g)
    {
         paint(g);
    }

    public void paint(Graphics g){
       //Move graphics to the true 0,0.
       g.translate(getInsets().left, getInsets().top);
       //Graphics2D g2d = (Graphics2D)g;

       //Draw the background
      g2d.drawImage(bg, 0, 0,this);
      
      //Background stars
      stars1.drawStars(g2d);
      
      //Foreground stars
      stars2.drawStars(g2d);
       
       
       //Display buffer
      g.drawImage(bi, 0, 0, this);
    }
   
    public void stop() {
    }

   
}














Please help me load sounds and graphics.
Offline CyanPrime
« Reply #1 - Posted 2009-09-09 15:54:53 »

bump
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #2 - Posted 2009-09-09 16:20:39 »

Can't test the code without resources and the other classes, could you post a zip with everything from the test?

Kev

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CyanPrime
« Reply #3 - Posted 2009-09-09 16:28:55 »

http://sites.google.com/site/cyanprime/appletgame.zip
Offline CyanPrime
« Reply #4 - Posted 2009-09-09 22:41:43 »

bump
Offline DzzD
« Reply #5 - Posted 2009-09-10 00:11:35 »


test.html just run fine here

EDIT:

and about sound : there is no sound playing but ....
1  
url = this.getClass().getResource("data/test" + i + ".au"); 


the above directory ( "data/test" ) is empty

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (78 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (121 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (179 views)
2013-05-12 17:10:36

kutucuk (179 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.118 seconds with 20 queries.