Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 1590 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

JGO Kernel


Medals: 85
Projects: 25


Coder, Trainee Pixel Artist, Game Reviewer


« 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.

 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!